Skip to content

Commit 9221e18

Browse files
feat: Adding ExecutorProvider support while creating BigQueryReadClient (#2072)
* Adding ExecutorProvider support while creating BigQueryReadClient * adding integration test * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 3e3fdc9 commit 9221e18

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-bigquerystorage'
5757
If you are using Gradle without BOM, add this to your dependencies:
5858

5959
```Groovy
60-
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.34.2'
60+
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.35.0'
6161
```
6262

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

6565
```Scala
66-
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.34.2"
66+
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.35.0"
6767
```
6868
<!-- {x-version-update-end} -->
6969

@@ -220,7 +220,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
220220
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquerystorage/java11.html
221221
[stability-image]: https://img.shields.io/badge/stability-stable-green
222222
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquerystorage.svg
223-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquerystorage/2.34.2
223+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquerystorage/2.35.0
224224
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
225225
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
226226
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/EnhancedBigQueryReadStub.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public static EnhancedBigQueryReadStub create(
7575
.setHeaderProvider(settings.getHeaderProvider())
7676
.setCredentialsProvider(settings.getCredentialsProvider())
7777
.setStreamWatchdogCheckInterval(settings.getStreamWatchdogCheckInterval())
78-
.setStreamWatchdogProvider(settings.getStreamWatchdogProvider());
78+
.setStreamWatchdogProvider(settings.getStreamWatchdogProvider())
79+
.setBackgroundExecutorProvider(settings.getBackgroundExecutorProvider());
7980

8081
baseSettingsBuilder
8182
.createReadSessionSettings()
@@ -195,4 +196,8 @@ public void shutdownNow() {
195196
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
196197
return stub.awaitTermination(duration, unit);
197198
}
199+
200+
public BigQueryReadStubSettings getStubSettings() {
201+
return stubSettings;
202+
}
198203
}

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertNotNull;
2323
import static org.junit.Assert.assertNull;
24+
import static org.junit.Assert.assertTrue;
2425

26+
import com.google.api.gax.core.InstantiatingExecutorProvider;
2527
import com.google.api.gax.rpc.ServerStream;
2628
import com.google.cloud.RetryOption;
2729
import com.google.cloud.ServiceOptions;
@@ -39,6 +41,7 @@
3941
import com.google.cloud.bigquery.TableInfo;
4042
import com.google.cloud.bigquery.TimePartitioning;
4143
import com.google.cloud.bigquery.storage.v1.BigQueryReadClient;
44+
import com.google.cloud.bigquery.storage.v1.BigQueryReadSettings;
4245
import com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest;
4346
import com.google.cloud.bigquery.storage.v1.DataFormat;
4447
import com.google.cloud.bigquery.storage.v1.ReadRowsRequest;
@@ -806,6 +809,56 @@ public void testStructAndArraySqlTypes() throws InterruptedException, IOExceptio
806809
assertEquals(rowAssertMessage, new Utf8("abc"), structRecord.get("str_field"));
807810
}
808811

812+
@Test
813+
public void testSimpleReadWithBackgroundExecutorProvider() throws IOException {
814+
BigQueryReadSettings bigQueryReadSettings =
815+
BigQueryReadSettings.newBuilder()
816+
.setBackgroundExecutorProvider(
817+
InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(14).build())
818+
.build();
819+
// Overriding the default client
820+
client = BigQueryReadClient.create(bigQueryReadSettings);
821+
assertTrue(
822+
client.getStub().getStubSettings().getBackgroundExecutorProvider()
823+
instanceof InstantiatingExecutorProvider);
824+
assertEquals(
825+
14,
826+
((InstantiatingExecutorProvider)
827+
client.getStub().getStubSettings().getBackgroundExecutorProvider())
828+
.getExecutorThreadCount());
829+
String table =
830+
BigQueryResource.FormatTableResource(
831+
/* projectId = */ "bigquery-public-data",
832+
/* datasetId = */ "samples",
833+
/* tableId = */ "shakespeare");
834+
835+
ReadSession session =
836+
client.createReadSession(
837+
/* parent = */ parentProjectId,
838+
/* readSession = */ ReadSession.newBuilder()
839+
.setTable(table)
840+
.setDataFormat(DataFormat.AVRO)
841+
.build(),
842+
/* maxStreamCount = */ 1);
843+
assertEquals(
844+
String.format(
845+
"Did not receive expected number of streams for table '%s' CreateReadSession response:%n%s",
846+
table, session.toString()),
847+
1,
848+
session.getStreamsCount());
849+
850+
ReadRowsRequest readRowsRequest =
851+
ReadRowsRequest.newBuilder().setReadStream(session.getStreams(0).getName()).build();
852+
853+
long rowCount = 0;
854+
ServerStream<ReadRowsResponse> stream = client.readRowsCallable().call(readRowsRequest);
855+
for (ReadRowsResponse response : stream) {
856+
rowCount += response.getRowCount();
857+
}
858+
859+
assertEquals(164_656, rowCount);
860+
}
861+
809862
/**
810863
* Reads to the specified row offset within the stream. If the stream does not have the desired
811864
* rows to read, it will read all of them.

0 commit comments

Comments
 (0)