Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.44.0')
implementation platform('com.google.cloud:libraries-bom:26.45.0')

implementation 'com.google.cloud:google-cloud-bigquery'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-bigquery:2.42.0'
implementation 'com.google.cloud:google-cloud-bigquery:2.42.1'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.42.0"
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.42.1"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -352,7 +352,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquery/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquery.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.42.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.42.1
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import com.google.api.services.bigquery.model.JobConfigurationQuery;
import com.google.api.services.bigquery.model.QueryParameter;
Expand All @@ -35,6 +36,7 @@
import com.google.cloud.bigquery.storage.v1.ArrowRecordBatch;
import com.google.cloud.bigquery.storage.v1.ArrowSchema;
import com.google.cloud.bigquery.storage.v1.BigQueryReadClient;
import com.google.cloud.bigquery.storage.v1.BigQueryReadSettings;
import com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest;
import com.google.cloud.bigquery.storage.v1.DataFormat;
import com.google.cloud.bigquery.storage.v1.ReadRowsRequest;
Expand Down Expand Up @@ -955,7 +957,12 @@ BigQueryResult highThroughPutRead(

try {
if (bqReadClient == null) { // if the read client isn't already initialized. Not thread safe.
bqReadClient = BigQueryReadClient.create();
BigQueryReadSettings settings =
BigQueryReadSettings.newBuilder()
.setCredentialsProvider(
FixedCredentialsProvider.create(bigQueryOptions.getCredentials()))
.build();
bqReadClient = BigQueryReadClient.create(settings);
}
String parent = String.format("projects/%s", destinationTable.getProject());
String srcTable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3249,6 +3249,57 @@ public void testExecuteSelectDefaultConnectionSettings() throws SQLException {
assertEquals(42, bigQueryResult.getTotalRows());
}

@Test
public void testExecuteSelectWithCredentials() throws SQLException {
// This test validate that executeSelect uses the same credential provided by the BigQuery
// object used to create the Connection client.
// This is done the following scenarios:
// 1. Validate that setting a valid credential executes the query.
// 2. Validate that setting an invalid credential causes failure.

// Scenario 1.
// Create a new bigQuery object but explicitly set the credentials.
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
BigQueryOptions bigQueryOptions =
bigqueryHelper
.getOptions()
.toBuilder()
.setCredentials(bigquery.getOptions().getCredentials())
.build();
BigQuery bigQueryGoodCredentials = bigQueryOptions.getService();

ConnectionSettings connectionSettings =
ConnectionSettings.newBuilder()
.setJobTimeoutMs(10L) // Force non-fast query to use BigQueryReadClient.
.setDefaultDataset(DatasetId.of(DATASET))
.build();
Connection connectionGoodCredentials =
bigQueryGoodCredentials.createConnection(connectionSettings);
String query =
"SELECT * FROM "
+ TABLE_ID_LARGE.getTable(); // Large query result is needed to use BigQueryReadClient.
BigQueryResult bigQueryResult = connectionGoodCredentials.executeSelect(query);
assertEquals(313348, bigQueryResult.getTotalRows());

// Scenario 2.
// Create a new bigQuery object but explicitly an invalid credential.
BigQueryOptions bigQueryOptionsBadCredentials =
bigqueryHelper
.getOptions()
.toBuilder()
.setCredentials(loadCredentials(FAKE_JSON_CRED_WITH_GOOGLE_DOMAIN))
.build();
BigQuery bigQueryBadCredentials = bigQueryOptionsBadCredentials.getService();
Connection connectionBadCredentials =
bigQueryBadCredentials.createConnection(connectionSettings);
try {
connectionBadCredentials.executeSelect(query);
fail(); // this line should not be reached
} catch (BigQuerySQLException e) {
assertNotNull(e);
}
}

/* TODO(prasmish): replicate the entire test case for executeSelect */
@Test
public void testQueryTimeStamp() throws InterruptedException {
Expand Down