diff --git a/README.md b/README.md index 030bed327..1303fb887 100644 --- a/README.md +++ b/README.md @@ -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" ``` @@ -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 diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java index 413243396..1f08bf4eb 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java @@ -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; @@ -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; @@ -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 = diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 63265d58a..9f0735094 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -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 {