From f50684a0b145ff95cebd9815c12d99f65eebfcf4 Mon Sep 17 00:00:00 2001 From: Julien Phalip Date: Wed, 22 Dec 2021 14:46:29 -0800 Subject: [PATCH 1/2] Add `append(rows)` method (without offset) to StreamWriter --- .../bigquery/storage/v1/JsonStreamWriter.java | 6 ++++-- .../bigquery/storage/v1/StreamWriter.java | 21 +++++++++++++------ .../bigquery/storage/v1/StreamWriterTest.java | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java index 6b20e89bcb..d5ecf2dc78 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java @@ -80,7 +80,8 @@ private JsonStreamWriter(Builder builder) /** * Writes a JSONArray that contains JSONObjects to the BigQuery table by first converting the JSON - * data to protobuf messages, then using StreamWriter's append() to write the data. + * data to protobuf messages, then using StreamWriter's append() to write the data at current + * end of stream. * * @param jsonArr The JSON array that contains JSONObjects to be written * @return ApiFuture returns an AppendRowsResponse message wrapped in an @@ -92,7 +93,8 @@ public ApiFuture append(JSONArray jsonArr) { /** * Writes a JSONArray that contains JSONObjects to the BigQuery table by first converting the JSON - * data to protobuf messages, then using StreamWriter's append() to write the data. + * data to protobuf messages, then using StreamWriter's append() to write the data at the + * specified offset. * * @param jsonArr The JSON array that contains JSONObjects to be written * @param offset Offset for deduplication diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java index 3df82733ba..1cac296a03 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java @@ -224,14 +224,23 @@ public void run(Throwable finalStatus) { } /** - * Schedules the writing of a message. + * Schedules the writing of rows at the end of current stream. * - *

Example of writing a message. + * @param rows the rows in serialized format to write to BigQuery. + * @return the append response wrapped in a future. + */ + public ApiFuture append(ProtoRows rows) { + return append(rows, -1); + } + + /** + * Schedules the writing of rows at given offset. + * + *

Example of writing rows with specific offset. * *

{@code
-   * AppendRowsRequest message;
-   * ApiFuture messageIdFuture = writer.append(message);
-   * ApiFutures.addCallback(messageIdFuture, new ApiFutureCallback() {
+   * ApiFuture future = writer.append(rows, 0);
+   * ApiFutures.addCallback(future, new ApiFutureCallback() {
    *   public void onSuccess(AppendRowsResponse response) {
    *     if (!response.hasError()) {
    *       System.out.println("written with offset: " + response.getAppendResult().getOffset());
@@ -247,7 +256,7 @@ public void run(Throwable finalStatus) {
    * }
* * @param rows the rows in serialized format to write to BigQuery. - * @param offset the offset of the first row. + * @param offset the offset of the first row. Provide -1 to write at the current end of stream. * @return the append response wrapped in a future. */ public ApiFuture append(ProtoRows rows, long offset) { diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java index 9310b70b24..92740d2a4e 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java @@ -131,7 +131,7 @@ private AppendRowsResponse createAppendResponseWithError(Status.Code code, Strin } private ApiFuture sendTestMessage(StreamWriter writer, String[] messages) { - return writer.append(createProtoRows(messages), -1); + return writer.append(createProtoRows(messages)); } private ApiFuture sendTestMessage( From fe0762affcdeb106b8998f4df63c123abc3ab2bc Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 23 Dec 2021 16:14:56 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../google/cloud/bigquery/storage/v1/JsonStreamWriter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java index d5ecf2dc78..eb614ff48e 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java @@ -80,8 +80,8 @@ private JsonStreamWriter(Builder builder) /** * Writes a JSONArray that contains JSONObjects to the BigQuery table by first converting the JSON - * data to protobuf messages, then using StreamWriter's append() to write the data at current - * end of stream. + * data to protobuf messages, then using StreamWriter's append() to write the data at current end + * of stream. * * @param jsonArr The JSON array that contains JSONObjects to be written * @return ApiFuture returns an AppendRowsResponse message wrapped in an