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..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,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(