Skip to content

Commit bb21e7b

Browse files
feat: bigquery Write API V1Beta2 public interface. (#637)
PiperOrigin-RevId: 339152802 Source-Author: Google APIs <noreply@google.com> Source-Date: Mon Oct 26 17:26:54 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: b3c2eb02e501d7eec36b4b08fcd981f32f8b4ff4 Source-Link: googleapis/googleapis@b3c2eb0
1 parent 88d4fc1 commit bb21e7b

File tree

58 files changed

+23138
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+23138
-133
lines changed

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/BaseBigQueryReadClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
*
3232
* <p>The Read API can be used to read data from BigQuery.
3333
*
34+
* <p>New code should use the v1 Read API going forward, if they don't use Write API at the same
35+
* time.
36+
*
3437
* <p>This class provides the ability to make remote calls to the backing service through method
3538
* calls that map to API methods. Sample code to get started:
3639
*

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/BigQueryWriteClient.java

Lines changed: 709 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.bigquery.storage.v1beta2;
17+
18+
import com.google.api.core.ApiFunction;
19+
import com.google.api.core.BetaApi;
20+
import com.google.api.gax.core.GoogleCredentialsProvider;
21+
import com.google.api.gax.core.InstantiatingExecutorProvider;
22+
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
23+
import com.google.api.gax.rpc.ApiClientHeaderProvider;
24+
import com.google.api.gax.rpc.ClientContext;
25+
import com.google.api.gax.rpc.ClientSettings;
26+
import com.google.api.gax.rpc.StreamingCallSettings;
27+
import com.google.api.gax.rpc.TransportChannelProvider;
28+
import com.google.api.gax.rpc.UnaryCallSettings;
29+
import com.google.cloud.bigquery.storage.v1beta2.stub.BigQueryWriteStubSettings;
30+
import java.io.IOException;
31+
import java.util.List;
32+
import javax.annotation.Generated;
33+
34+
// AUTO-GENERATED DOCUMENTATION AND CLASS
35+
/**
36+
* Settings class to configure an instance of {@link BigQueryWriteClient}.
37+
*
38+
* <p>The default instance has everything set to sensible defaults:
39+
*
40+
* <ul>
41+
* <li>The default service address (bigquerystorage.googleapis.com) and default port (443) are
42+
* used.
43+
* <li>Credentials are acquired automatically through Application Default Credentials.
44+
* <li>Retries are configured for idempotent methods but not for non-idempotent methods.
45+
* </ul>
46+
*
47+
* <p>The builder of this class is recursive, so contained classes are themselves builders. When
48+
* build() is called, the tree of builders is called to create the complete settings object.
49+
*
50+
* <p>For example, to set the total timeout of createWriteStream to 30 seconds:
51+
*
52+
* <pre>
53+
* <code>
54+
* BigQueryWriteSettings.Builder bigQueryWriteSettingsBuilder =
55+
* BigQueryWriteSettings.newBuilder();
56+
* bigQueryWriteSettingsBuilder
57+
* .createWriteStreamSettings()
58+
* .setRetrySettings(
59+
* bigQueryWriteSettingsBuilder.createWriteStreamSettings().getRetrySettings().toBuilder()
60+
* .setTotalTimeout(Duration.ofSeconds(30))
61+
* .build());
62+
* BigQueryWriteSettings bigQueryWriteSettings = bigQueryWriteSettingsBuilder.build();
63+
* </code>
64+
* </pre>
65+
*/
66+
@Generated("by gapic-generator")
67+
@BetaApi
68+
public class BigQueryWriteSettings extends ClientSettings<BigQueryWriteSettings> {
69+
/** Returns the object with the settings used for calls to createWriteStream. */
70+
public UnaryCallSettings<CreateWriteStreamRequest, WriteStream> createWriteStreamSettings() {
71+
return ((BigQueryWriteStubSettings) getStubSettings()).createWriteStreamSettings();
72+
}
73+
74+
/** Returns the object with the settings used for calls to appendRows. */
75+
public StreamingCallSettings<AppendRowsRequest, AppendRowsResponse> appendRowsSettings() {
76+
return ((BigQueryWriteStubSettings) getStubSettings()).appendRowsSettings();
77+
}
78+
79+
/** Returns the object with the settings used for calls to getWriteStream. */
80+
public UnaryCallSettings<GetWriteStreamRequest, WriteStream> getWriteStreamSettings() {
81+
return ((BigQueryWriteStubSettings) getStubSettings()).getWriteStreamSettings();
82+
}
83+
84+
/** Returns the object with the settings used for calls to finalizeWriteStream. */
85+
public UnaryCallSettings<FinalizeWriteStreamRequest, FinalizeWriteStreamResponse>
86+
finalizeWriteStreamSettings() {
87+
return ((BigQueryWriteStubSettings) getStubSettings()).finalizeWriteStreamSettings();
88+
}
89+
90+
/** Returns the object with the settings used for calls to batchCommitWriteStreams. */
91+
public UnaryCallSettings<BatchCommitWriteStreamsRequest, BatchCommitWriteStreamsResponse>
92+
batchCommitWriteStreamsSettings() {
93+
return ((BigQueryWriteStubSettings) getStubSettings()).batchCommitWriteStreamsSettings();
94+
}
95+
96+
/** Returns the object with the settings used for calls to flushRows. */
97+
public UnaryCallSettings<FlushRowsRequest, FlushRowsResponse> flushRowsSettings() {
98+
return ((BigQueryWriteStubSettings) getStubSettings()).flushRowsSettings();
99+
}
100+
101+
public static final BigQueryWriteSettings create(BigQueryWriteStubSettings stub)
102+
throws IOException {
103+
return new BigQueryWriteSettings.Builder(stub.toBuilder()).build();
104+
}
105+
106+
/** Returns a builder for the default ExecutorProvider for this service. */
107+
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
108+
return BigQueryWriteStubSettings.defaultExecutorProviderBuilder();
109+
}
110+
111+
/** Returns the default service endpoint. */
112+
public static String getDefaultEndpoint() {
113+
return BigQueryWriteStubSettings.getDefaultEndpoint();
114+
}
115+
116+
/** Returns the default service scopes. */
117+
public static List<String> getDefaultServiceScopes() {
118+
return BigQueryWriteStubSettings.getDefaultServiceScopes();
119+
}
120+
121+
/** Returns a builder for the default credentials for this service. */
122+
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
123+
return BigQueryWriteStubSettings.defaultCredentialsProviderBuilder();
124+
}
125+
126+
/** Returns a builder for the default ChannelProvider for this service. */
127+
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
128+
return BigQueryWriteStubSettings.defaultGrpcTransportProviderBuilder();
129+
}
130+
131+
public static TransportChannelProvider defaultTransportChannelProvider() {
132+
return BigQueryWriteStubSettings.defaultTransportChannelProvider();
133+
}
134+
135+
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
136+
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
137+
return BigQueryWriteStubSettings.defaultApiClientHeaderProviderBuilder();
138+
}
139+
140+
/** Returns a new builder for this class. */
141+
public static Builder newBuilder() {
142+
return Builder.createDefault();
143+
}
144+
145+
/** Returns a new builder for this class. */
146+
public static Builder newBuilder(ClientContext clientContext) {
147+
return new Builder(clientContext);
148+
}
149+
150+
/** Returns a builder containing all the values of this settings class. */
151+
public Builder toBuilder() {
152+
return new Builder(this);
153+
}
154+
155+
protected BigQueryWriteSettings(Builder settingsBuilder) throws IOException {
156+
super(settingsBuilder);
157+
}
158+
159+
/** Builder for BigQueryWriteSettings. */
160+
public static class Builder extends ClientSettings.Builder<BigQueryWriteSettings, Builder> {
161+
protected Builder() throws IOException {
162+
this((ClientContext) null);
163+
}
164+
165+
protected Builder(ClientContext clientContext) {
166+
super(BigQueryWriteStubSettings.newBuilder(clientContext));
167+
}
168+
169+
private static Builder createDefault() {
170+
return new Builder(BigQueryWriteStubSettings.newBuilder());
171+
}
172+
173+
protected Builder(BigQueryWriteSettings settings) {
174+
super(settings.getStubSettings().toBuilder());
175+
}
176+
177+
protected Builder(BigQueryWriteStubSettings.Builder stubSettings) {
178+
super(stubSettings);
179+
}
180+
181+
public BigQueryWriteStubSettings.Builder getStubSettingsBuilder() {
182+
return ((BigQueryWriteStubSettings.Builder) getStubSettings());
183+
}
184+
185+
// NEXT_MAJOR_VER: remove 'throws Exception'
186+
/**
187+
* Applies the given settings updater function to all of the unary API methods in this service.
188+
*
189+
* <p>Note: This method does not support applying settings to streaming methods.
190+
*/
191+
public Builder applyToAllUnaryMethods(
192+
ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) throws Exception {
193+
super.applyToAllUnaryMethods(
194+
getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater);
195+
return this;
196+
}
197+
198+
/** Returns the builder for the settings used for calls to createWriteStream. */
199+
public UnaryCallSettings.Builder<CreateWriteStreamRequest, WriteStream>
200+
createWriteStreamSettings() {
201+
return getStubSettingsBuilder().createWriteStreamSettings();
202+
}
203+
204+
/** Returns the builder for the settings used for calls to appendRows. */
205+
public StreamingCallSettings.Builder<AppendRowsRequest, AppendRowsResponse>
206+
appendRowsSettings() {
207+
return getStubSettingsBuilder().appendRowsSettings();
208+
}
209+
210+
/** Returns the builder for the settings used for calls to getWriteStream. */
211+
public UnaryCallSettings.Builder<GetWriteStreamRequest, WriteStream> getWriteStreamSettings() {
212+
return getStubSettingsBuilder().getWriteStreamSettings();
213+
}
214+
215+
/** Returns the builder for the settings used for calls to finalizeWriteStream. */
216+
public UnaryCallSettings.Builder<FinalizeWriteStreamRequest, FinalizeWriteStreamResponse>
217+
finalizeWriteStreamSettings() {
218+
return getStubSettingsBuilder().finalizeWriteStreamSettings();
219+
}
220+
221+
/** Returns the builder for the settings used for calls to batchCommitWriteStreams. */
222+
public UnaryCallSettings.Builder<
223+
BatchCommitWriteStreamsRequest, BatchCommitWriteStreamsResponse>
224+
batchCommitWriteStreamsSettings() {
225+
return getStubSettingsBuilder().batchCommitWriteStreamsSettings();
226+
}
227+
228+
/** Returns the builder for the settings used for calls to flushRows. */
229+
public UnaryCallSettings.Builder<FlushRowsRequest, FlushRowsResponse> flushRowsSettings() {
230+
return getStubSettingsBuilder().flushRowsSettings();
231+
}
232+
233+
@Override
234+
public BigQueryWriteSettings build() throws IOException {
235+
return new BigQueryWriteSettings(this);
236+
}
237+
}
238+
}

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/package-info.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
*
2626
* <p>The Read API can be used to read data from BigQuery.
2727
*
28+
* <p>New code should use the v1 Read API going forward, if they don't use Write API at the same
29+
* time.
30+
*
2831
* <p>Sample for BaseBigQueryReadClient:
2932
*
3033
* <pre>
@@ -37,6 +40,24 @@
3740
* }
3841
* </code>
3942
* </pre>
43+
*
44+
* =================== BigQueryWriteClient ===================
45+
*
46+
* <p>Service Description: BigQuery Write API.
47+
*
48+
* <p>The Write API can be used to write data to BigQuery.
49+
*
50+
* <p>Sample for BigQueryWriteClient:
51+
*
52+
* <pre>
53+
* <code>
54+
* try (BigQueryWriteClient bigQueryWriteClient = BigQueryWriteClient.create()) {
55+
* TableName parent = TableName.of("[PROJECT]", "[DATASET]", "[TABLE]");
56+
* WriteStream writeStream = WriteStream.newBuilder().build();
57+
* WriteStream response = bigQueryWriteClient.createWriteStream(parent, writeStream);
58+
* }
59+
* </code>
60+
* </pre>
4061
*/
4162
@Generated("by gapic-generator")
4263
package com.google.cloud.bigquery.storage.v1beta2;

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/BigQueryReadStubSettings.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public class BigQueryReadStubSettings extends StubSettings<BigQueryReadStubSetti
8585
private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
8686
ImmutableList.<String>builder()
8787
.add("https://www.googleapis.com/auth/bigquery")
88+
.add("https://www.googleapis.com/auth/bigquery.insertdata")
8889
.add("https://www.googleapis.com/auth/bigquery.readonly")
8990
.add("https://www.googleapis.com/auth/cloud-platform")
9091
.build();
@@ -206,6 +207,18 @@ public static class Builder extends StubSettings.Builder<BigQueryReadStubSetting
206207
ImmutableSet.copyOf(
207208
Lists.<StatusCode.Code>newArrayList(
208209
StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
210+
definitions.put(
211+
"retry_policy_4_codes",
212+
ImmutableSet.copyOf(
213+
Lists.<StatusCode.Code>newArrayList(
214+
StatusCode.Code.DEADLINE_EXCEEDED,
215+
StatusCode.Code.UNAVAILABLE,
216+
StatusCode.Code.RESOURCE_EXHAUSTED)));
217+
definitions.put(
218+
"retry_policy_6_codes",
219+
ImmutableSet.copyOf(
220+
Lists.<StatusCode.Code>newArrayList(
221+
StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
209222
definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList()));
210223
definitions.put(
211224
"retry_policy_3_codes",
@@ -215,6 +228,11 @@ public static class Builder extends StubSettings.Builder<BigQueryReadStubSetting
215228
definitions.put(
216229
"retry_policy_2_codes",
217230
ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList(StatusCode.Code.UNAVAILABLE)));
231+
definitions.put(
232+
"retry_policy_5_codes",
233+
ImmutableSet.copyOf(
234+
Lists.<StatusCode.Code>newArrayList(
235+
StatusCode.Code.UNAVAILABLE, StatusCode.Code.RESOURCE_EXHAUSTED)));
218236
RETRYABLE_CODE_DEFINITIONS = definitions.build();
219237
}
220238

@@ -234,6 +252,17 @@ public static class Builder extends StubSettings.Builder<BigQueryReadStubSetting
234252
.setTotalTimeout(Duration.ofMillis(600000L))
235253
.build();
236254
definitions.put("retry_policy_1_params", settings);
255+
settings =
256+
RetrySettings.newBuilder()
257+
.setInitialRetryDelay(Duration.ofMillis(100L))
258+
.setRetryDelayMultiplier(1.3)
259+
.setMaxRetryDelay(Duration.ofMillis(60000L))
260+
.setInitialRpcTimeout(Duration.ofMillis(600000L))
261+
.setRpcTimeoutMultiplier(1.0)
262+
.setMaxRpcTimeout(Duration.ofMillis(600000L))
263+
.setTotalTimeout(Duration.ofMillis(600000L))
264+
.build();
265+
definitions.put("retry_policy_6_params", settings);
237266
settings =
238267
RetrySettings.newBuilder()
239268
.setInitialRetryDelay(Duration.ofMillis(100L))
@@ -256,6 +285,28 @@ public static class Builder extends StubSettings.Builder<BigQueryReadStubSetting
256285
.setTotalTimeout(Duration.ofMillis(86400000L))
257286
.build();
258287
definitions.put("retry_policy_2_params", settings);
288+
settings =
289+
RetrySettings.newBuilder()
290+
.setInitialRetryDelay(Duration.ofMillis(100L))
291+
.setRetryDelayMultiplier(1.3)
292+
.setMaxRetryDelay(Duration.ofMillis(60000L))
293+
.setInitialRpcTimeout(Duration.ofMillis(600000L))
294+
.setRpcTimeoutMultiplier(1.0)
295+
.setMaxRpcTimeout(Duration.ofMillis(600000L))
296+
.setTotalTimeout(Duration.ofMillis(600000L))
297+
.build();
298+
definitions.put("retry_policy_4_params", settings);
299+
settings =
300+
RetrySettings.newBuilder()
301+
.setInitialRetryDelay(Duration.ofMillis(100L))
302+
.setRetryDelayMultiplier(1.3)
303+
.setMaxRetryDelay(Duration.ofMillis(60000L))
304+
.setInitialRpcTimeout(Duration.ofMillis(86400000L))
305+
.setRpcTimeoutMultiplier(1.0)
306+
.setMaxRpcTimeout(Duration.ofMillis(86400000L))
307+
.setTotalTimeout(Duration.ofMillis(86400000L))
308+
.build();
309+
definitions.put("retry_policy_5_params", settings);
259310
settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build();
260311
definitions.put("no_retry_params", settings);
261312
RETRY_PARAM_DEFINITIONS = definitions.build();

0 commit comments

Comments
 (0)