Skip to content

Commit fbb5321

Browse files
docs: improve documentation for write client (#1560)
* docs: improve documentation for write client feat: update default timeout/retry information feat: update parent annotation for BatchCommitWriteStreamsRequest feat: expose additional StorageError enum values PiperOrigin-RevId: 431973595 Source-Link: googleapis/googleapis@25d691b Source-Link: https://github.com/googleapis/googleapis-gen/commit/0ca21879ae3136a2d71fa824b49dfaf8a0ae0f2e Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMGNhMjE4NzlhZTMxMzZhMmQ3MWZhODI0YjQ5ZGZhZjhhMGFlMGYyZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 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 b495359 commit fbb5321

File tree

13 files changed

+321
-138
lines changed

13 files changed

+321
-138
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ public final UnaryCallable<CreateWriteStreamRequest, WriteStream> createWriteStr
294294
* `BatchCommitWriteStreams` rpc.
295295
* </ul>
296296
*
297+
* <p>Note: For users coding against the gRPC api directly, it may be necessary to supply the
298+
* x-goog-request-params system parameter with `write_stream=&lt;full_write_stream_name&gt;`.
299+
*
300+
* <p>More information about system parameters:
301+
* https://cloud.google.com/apis/docs/system-parameters
302+
*
297303
* <p>Sample code:
298304
*
299305
* <pre>{@code
@@ -523,7 +529,36 @@ public final FinalizeWriteStreamResponse finalizeWriteStream(FinalizeWriteStream
523529
*
524530
* <pre>{@code
525531
* try (BigQueryWriteClient bigQueryWriteClient = BigQueryWriteClient.create()) {
526-
* String parent = "parent-995424086";
532+
* TableName parent = TableName.of("[PROJECT]", "[DATASET]", "[TABLE]");
533+
* BatchCommitWriteStreamsResponse response =
534+
* bigQueryWriteClient.batchCommitWriteStreams(parent);
535+
* }
536+
* }</pre>
537+
*
538+
* @param parent Required. Parent table that all the streams should belong to, in the form of
539+
* `projects/{project}/datasets/{dataset}/tables/{table}`.
540+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
541+
*/
542+
public final BatchCommitWriteStreamsResponse batchCommitWriteStreams(TableName parent) {
543+
BatchCommitWriteStreamsRequest request =
544+
BatchCommitWriteStreamsRequest.newBuilder()
545+
.setParent(parent == null ? null : parent.toString())
546+
.build();
547+
return batchCommitWriteStreams(request);
548+
}
549+
550+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
551+
/**
552+
* Atomically commits a group of `PENDING` streams that belong to the same `parent` table.
553+
*
554+
* <p>Streams must be finalized before commit and cannot be committed multiple times. Once a
555+
* stream is committed, data in the stream becomes available for read operations.
556+
*
557+
* <p>Sample code:
558+
*
559+
* <pre>{@code
560+
* try (BigQueryWriteClient bigQueryWriteClient = BigQueryWriteClient.create()) {
561+
* String parent = TableName.of("[PROJECT]", "[DATASET]", "[TABLE]").toString();
527562
* BatchCommitWriteStreamsResponse response =
528563
* bigQueryWriteClient.batchCommitWriteStreams(parent);
529564
* }
@@ -552,7 +587,7 @@ public final BatchCommitWriteStreamsResponse batchCommitWriteStreams(String pare
552587
* try (BigQueryWriteClient bigQueryWriteClient = BigQueryWriteClient.create()) {
553588
* BatchCommitWriteStreamsRequest request =
554589
* BatchCommitWriteStreamsRequest.newBuilder()
555-
* .setParent("parent-995424086")
590+
* .setParent(TableName.of("[PROJECT]", "[DATASET]", "[TABLE]").toString())
556591
* .addAllWriteStreams(new ArrayList<String>())
557592
* .build();
558593
* BatchCommitWriteStreamsResponse response =
@@ -581,7 +616,7 @@ public final BatchCommitWriteStreamsResponse batchCommitWriteStreams(
581616
* try (BigQueryWriteClient bigQueryWriteClient = BigQueryWriteClient.create()) {
582617
* BatchCommitWriteStreamsRequest request =
583618
* BatchCommitWriteStreamsRequest.newBuilder()
584-
* .setParent("parent-995424086")
619+
* .setParent(TableName.of("[PROJECT]", "[DATASET]", "[TABLE]").toString())
585620
* .addAllWriteStreams(new ArrayList<String>())
586621
* .build();
587622
* ApiFuture<BatchCommitWriteStreamsResponse> future =

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/gapic_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"methods": ["appendRowsCallable"]
3333
},
3434
"BatchCommitWriteStreams": {
35-
"methods": ["batchCommitWriteStreams", "batchCommitWriteStreams", "batchCommitWriteStreamsCallable"]
35+
"methods": ["batchCommitWriteStreams", "batchCommitWriteStreams", "batchCommitWriteStreams", "batchCommitWriteStreamsCallable"]
3636
},
3737
"CreateWriteStream": {
3838
"methods": ["createWriteStream", "createWriteStream", "createWriteStream", "createWriteStreamCallable"]

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ public static class Builder extends StubSettings.Builder<BigQueryReadStubSetting
214214
definitions.put(
215215
"retry_policy_1_codes",
216216
ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList(StatusCode.Code.UNAVAILABLE)));
217+
definitions.put(
218+
"retry_policy_2_codes",
219+
ImmutableSet.copyOf(
220+
Lists.<StatusCode.Code>newArrayList(
221+
StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
217222
RETRYABLE_CODE_DEFINITIONS = definitions.build();
218223
}
219224

@@ -244,6 +249,17 @@ public static class Builder extends StubSettings.Builder<BigQueryReadStubSetting
244249
.setTotalTimeout(Duration.ofMillis(86400000L))
245250
.build();
246251
definitions.put("retry_policy_1_params", settings);
252+
settings =
253+
RetrySettings.newBuilder()
254+
.setInitialRetryDelay(Duration.ofMillis(100L))
255+
.setRetryDelayMultiplier(1.3)
256+
.setMaxRetryDelay(Duration.ofMillis(60000L))
257+
.setInitialRpcTimeout(Duration.ofMillis(600000L))
258+
.setRpcTimeoutMultiplier(1.0)
259+
.setMaxRpcTimeout(Duration.ofMillis(600000L))
260+
.setTotalTimeout(Duration.ofMillis(600000L))
261+
.build();
262+
definitions.put("retry_policy_2_params", settings);
247263
RETRY_PARAM_DEFINITIONS = definitions.build();
248264
}
249265

@@ -302,8 +318,8 @@ private static Builder initDefaults(Builder builder) {
302318

303319
builder
304320
.splitReadStreamSettings()
305-
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
306-
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
321+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes"))
322+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params"));
307323

308324
return builder;
309325
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static class Builder extends StubSettings.Builder<BigQueryWriteStubSettin
242242
ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions =
243243
ImmutableMap.builder();
244244
definitions.put(
245-
"retry_policy_2_codes",
245+
"retry_policy_4_codes",
246246
ImmutableSet.copyOf(
247247
Lists.<StatusCode.Code>newArrayList(
248248
StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
@@ -267,7 +267,7 @@ public static class Builder extends StubSettings.Builder<BigQueryWriteStubSettin
267267
.setMaxRpcTimeout(Duration.ofMillis(600000L))
268268
.setTotalTimeout(Duration.ofMillis(600000L))
269269
.build();
270-
definitions.put("retry_policy_2_params", settings);
270+
definitions.put("retry_policy_4_params", settings);
271271
settings =
272272
RetrySettings.newBuilder()
273273
.setInitialRetryDelay(Duration.ofMillis(100L))
@@ -341,28 +341,28 @@ private static Builder createDefault() {
341341
private static Builder initDefaults(Builder builder) {
342342
builder
343343
.createWriteStreamSettings()
344-
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes"))
345-
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params"));
344+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_4_codes"))
345+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_4_params"));
346346

347347
builder
348348
.getWriteStreamSettings()
349-
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes"))
350-
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params"));
349+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_4_codes"))
350+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_4_params"));
351351

352352
builder
353353
.finalizeWriteStreamSettings()
354-
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes"))
355-
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params"));
354+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_4_codes"))
355+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_4_params"));
356356

357357
builder
358358
.batchCommitWriteStreamsSettings()
359-
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes"))
360-
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params"));
359+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_4_codes"))
360+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_4_params"));
361361

362362
builder
363363
.flushRowsSettings()
364-
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes"))
365-
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params"));
364+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_4_codes"))
365+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_4_params"));
366366

367367
return builder;
368368
}

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,46 @@ public void batchCommitWriteStreamsTest() throws Exception {
393393
.build();
394394
mockBigQueryWrite.addResponse(expectedResponse);
395395

396+
TableName parent = TableName.of("[PROJECT]", "[DATASET]", "[TABLE]");
397+
398+
BatchCommitWriteStreamsResponse actualResponse = client.batchCommitWriteStreams(parent);
399+
Assert.assertEquals(expectedResponse, actualResponse);
400+
401+
List<AbstractMessage> actualRequests = mockBigQueryWrite.getRequests();
402+
Assert.assertEquals(1, actualRequests.size());
403+
BatchCommitWriteStreamsRequest actualRequest =
404+
((BatchCommitWriteStreamsRequest) actualRequests.get(0));
405+
406+
Assert.assertEquals(parent.toString(), actualRequest.getParent());
407+
Assert.assertTrue(
408+
channelProvider.isHeaderSent(
409+
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
410+
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
411+
}
412+
413+
@Test
414+
public void batchCommitWriteStreamsExceptionTest() throws Exception {
415+
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
416+
mockBigQueryWrite.addException(exception);
417+
418+
try {
419+
TableName parent = TableName.of("[PROJECT]", "[DATASET]", "[TABLE]");
420+
client.batchCommitWriteStreams(parent);
421+
Assert.fail("No exception raised");
422+
} catch (InvalidArgumentException e) {
423+
// Expected exception.
424+
}
425+
}
426+
427+
@Test
428+
public void batchCommitWriteStreamsTest2() throws Exception {
429+
BatchCommitWriteStreamsResponse expectedResponse =
430+
BatchCommitWriteStreamsResponse.newBuilder()
431+
.setCommitTime(Timestamp.newBuilder().build())
432+
.addAllStreamErrors(new ArrayList<StorageError>())
433+
.build();
434+
mockBigQueryWrite.addResponse(expectedResponse);
435+
396436
String parent = "parent-995424086";
397437

398438
BatchCommitWriteStreamsResponse actualResponse = client.batchCommitWriteStreams(parent);
@@ -411,7 +451,7 @@ public void batchCommitWriteStreamsTest() throws Exception {
411451
}
412452

413453
@Test
414-
public void batchCommitWriteStreamsExceptionTest() throws Exception {
454+
public void batchCommitWriteStreamsExceptionTest2() throws Exception {
415455
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
416456
mockBigQueryWrite.addException(exception);
417457

grpc-google-cloud-bigquerystorage-v1/src/main/java/com/google/cloud/bigquery/storage/v1/BigQueryWriteGrpc.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ public void createWriteStream(
424424
* * For PENDING streams, data is not made visible until the stream itself is
425425
* finalized (via the `FinalizeWriteStream` rpc), and the stream is explicitly
426426
* committed via the `BatchCommitWriteStreams` rpc.
427+
* Note: For users coding against the gRPC api directly, it may be
428+
* necessary to supply the x-goog-request-params system parameter
429+
* with `write_stream=&lt;full_write_stream_name&gt;`.
430+
* More information about system parameters:
431+
* https://cloud.google.com/apis/docs/system-parameters
427432
* </pre>
428433
*/
429434
public io.grpc.stub.StreamObserver<com.google.cloud.bigquery.storage.v1.AppendRowsRequest>
@@ -625,6 +630,11 @@ public void createWriteStream(
625630
* * For PENDING streams, data is not made visible until the stream itself is
626631
* finalized (via the `FinalizeWriteStream` rpc), and the stream is explicitly
627632
* committed via the `BatchCommitWriteStreams` rpc.
633+
* Note: For users coding against the gRPC api directly, it may be
634+
* necessary to supply the x-goog-request-params system parameter
635+
* with `write_stream=&lt;full_write_stream_name&gt;`.
636+
* More information about system parameters:
637+
* https://cloud.google.com/apis/docs/system-parameters
628638
* </pre>
629639
*/
630640
public io.grpc.stub.StreamObserver<com.google.cloud.bigquery.storage.v1.AppendRowsRequest>

proto-google-cloud-bigquerystorage-v1/src/main/java/com/google/cloud/bigquery/storage/v1/AppendRowsRequest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,9 +1387,9 @@ public RowsCase getRowsCase() {
13871387
* If provided for subsequent requests, it must match the value of the first
13881388
* request.
13891389
* For explicitly created write streams, the format is:
1390-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
1390+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
13911391
* For the special default stream, the format is:
1392-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
1392+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
13931393
* </pre>
13941394
*
13951395
* <code>
@@ -1419,9 +1419,9 @@ public java.lang.String getWriteStream() {
14191419
* If provided for subsequent requests, it must match the value of the first
14201420
* request.
14211421
* For explicitly created write streams, the format is:
1422-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
1422+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
14231423
* For the special default stream, the format is:
1424-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
1424+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
14251425
* </pre>
14261426
*
14271427
* <code>
@@ -2048,9 +2048,9 @@ public Builder clearRows() {
20482048
* If provided for subsequent requests, it must match the value of the first
20492049
* request.
20502050
* For explicitly created write streams, the format is:
2051-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
2051+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
20522052
* For the special default stream, the format is:
2053-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
2053+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
20542054
* </pre>
20552055
*
20562056
* <code>
@@ -2079,9 +2079,9 @@ public java.lang.String getWriteStream() {
20792079
* If provided for subsequent requests, it must match the value of the first
20802080
* request.
20812081
* For explicitly created write streams, the format is:
2082-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
2082+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
20832083
* For the special default stream, the format is:
2084-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
2084+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
20852085
* </pre>
20862086
*
20872087
* <code>
@@ -2110,9 +2110,9 @@ public com.google.protobuf.ByteString getWriteStreamBytes() {
21102110
* If provided for subsequent requests, it must match the value of the first
21112111
* request.
21122112
* For explicitly created write streams, the format is:
2113-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
2113+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
21142114
* For the special default stream, the format is:
2115-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
2115+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
21162116
* </pre>
21172117
*
21182118
* <code>
@@ -2140,9 +2140,9 @@ public Builder setWriteStream(java.lang.String value) {
21402140
* If provided for subsequent requests, it must match the value of the first
21412141
* request.
21422142
* For explicitly created write streams, the format is:
2143-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
2143+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
21442144
* For the special default stream, the format is:
2145-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
2145+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
21462146
* </pre>
21472147
*
21482148
* <code>
@@ -2166,9 +2166,9 @@ public Builder clearWriteStream() {
21662166
* If provided for subsequent requests, it must match the value of the first
21672167
* request.
21682168
* For explicitly created write streams, the format is:
2169-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
2169+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
21702170
* For the special default stream, the format is:
2171-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
2171+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
21722172
* </pre>
21732173
*
21742174
* <code>

proto-google-cloud-bigquerystorage-v1/src/main/java/com/google/cloud/bigquery/storage/v1/AppendRowsRequestOrBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public interface AppendRowsRequestOrBuilder
3232
* If provided for subsequent requests, it must match the value of the first
3333
* request.
3434
* For explicitly created write streams, the format is:
35-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
35+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
3636
* For the special default stream, the format is:
37-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
37+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
3838
* </pre>
3939
*
4040
* <code>
@@ -53,9 +53,9 @@ public interface AppendRowsRequestOrBuilder
5353
* If provided for subsequent requests, it must match the value of the first
5454
* request.
5555
* For explicitly created write streams, the format is:
56-
* `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
56+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/{id}`
5757
* For the special default stream, the format is:
58-
* `projects/{project}/datasets/{dataset}/tables/{table}/_default`.
58+
* * `projects/{project}/datasets/{dataset}/tables/{table}/streams/_default`.
5959
* </pre>
6060
*
6161
* <code>

0 commit comments

Comments
 (0)