diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2.java index 1d001d5bbb..6c4973043c 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2.java @@ -17,6 +17,8 @@ import com.google.api.core.ApiFuture; import com.google.api.core.SettableApiFuture; +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.rpc.TransportChannelProvider; import com.google.cloud.bigquery.storage.v1beta2.StreamConnection.DoneCallback; import com.google.cloud.bigquery.storage.v1beta2.StreamConnection.RequestCallback; import com.google.common.base.Preconditions; @@ -24,6 +26,7 @@ import io.grpc.Status; import io.grpc.Status.Code; import io.grpc.StatusRuntimeException; +import java.io.IOException; import java.util.Deque; import java.util.LinkedList; import java.util.concurrent.TimeUnit; @@ -36,8 +39,6 @@ /** * A BigQuery Stream Writer that can be used to write data into BigQuery Table. * - *
TODO: Add credential support. - * *
TODO: Attach schema. * *
TODO: Attach traceId.
@@ -104,6 +105,16 @@ public class StreamWriterV2 implements AutoCloseable {
@GuardedBy("lock")
private final Deque For performance, this client benefits from having multiple underlying connections. See
+ * {@link com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.Builder#setPoolSize(int)}.
+ */
+ public Builder setChannelProvider(TransportChannelProvider channelProvider) {
+ this.channelProvider =
+ Preconditions.checkNotNull(channelProvider, "ChannelProvider is null.");
+ return this;
+ }
+
+ /** {@code CredentialsProvider} to use to create Credentials to authenticate calls. */
+ public Builder setCredentialsProvider(CredentialsProvider credentialsProvider) {
+ this.credentialsProvider =
+ Preconditions.checkNotNull(credentialsProvider, "CredentialsProvider is null.");
+ return this;
+ }
+
/** Builds the {@code StreamWriterV2}. */
- public StreamWriterV2 build() {
+ public StreamWriterV2 build() throws IOException {
return new StreamWriterV2(this);
}
}
diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2Test.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2Test.java
index bb82e79435..be51412c2e 100644
--- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2Test.java
+++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2Test.java
@@ -31,6 +31,7 @@
import com.google.protobuf.Int64Value;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -81,7 +82,7 @@ public void tearDown() throws Exception {
serviceHelper.stop();
}
- private StreamWriterV2 getTestStreamWriterV2() {
+ private StreamWriterV2 getTestStreamWriterV2() throws IOException {
return StreamWriterV2.newBuilder(TEST_STREAM, client).build();
}
@@ -158,6 +159,20 @@ public void run() {
appendThread.interrupt();
}
+ @Test
+ public void testBuildBigQueryWriteClientInWriter() throws Exception {
+ StreamWriterV2 writer =
+ StreamWriterV2.newBuilder(TEST_STREAM)
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .setChannelProvider(serviceHelper.createChannelProvider())
+ .build();
+
+ testBigQueryWrite.addResponse(createAppendResponse(0));
+ ApiFuture