Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit cb8b0ad

Browse files
authored
feat: support append() without offset in StreamWriter (#1452)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-bigquerystorage/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> ☕️
1 parent e47ac79 commit cb8b0ad

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ private JsonStreamWriter(Builder builder)
8080

8181
/**
8282
* Writes a JSONArray that contains JSONObjects to the BigQuery table by first converting the JSON
83-
* data to protobuf messages, then using StreamWriter's append() to write the data.
83+
* data to protobuf messages, then using StreamWriter's append() to write the data at current end
84+
* of stream.
8485
*
8586
* @param jsonArr The JSON array that contains JSONObjects to be written
8687
* @return ApiFuture<AppendRowsResponse> returns an AppendRowsResponse message wrapped in an
@@ -92,7 +93,8 @@ public ApiFuture<AppendRowsResponse> append(JSONArray jsonArr) {
9293

9394
/**
9495
* Writes a JSONArray that contains JSONObjects to the BigQuery table by first converting the JSON
95-
* data to protobuf messages, then using StreamWriter's append() to write the data.
96+
* data to protobuf messages, then using StreamWriter's append() to write the data at the
97+
* specified offset.
9698
*
9799
* @param jsonArr The JSON array that contains JSONObjects to be written
98100
* @param offset Offset for deduplication

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,23 @@ public void run(Throwable finalStatus) {
224224
}
225225

226226
/**
227-
* Schedules the writing of a message.
227+
* Schedules the writing of rows at the end of current stream.
228228
*
229-
* <p>Example of writing a message.
229+
* @param rows the rows in serialized format to write to BigQuery.
230+
* @return the append response wrapped in a future.
231+
*/
232+
public ApiFuture<AppendRowsResponse> append(ProtoRows rows) {
233+
return append(rows, -1);
234+
}
235+
236+
/**
237+
* Schedules the writing of rows at given offset.
238+
*
239+
* <p>Example of writing rows with specific offset.
230240
*
231241
* <pre>{@code
232-
* AppendRowsRequest message;
233-
* ApiFuture<AppendRowsResponse> messageIdFuture = writer.append(message);
234-
* ApiFutures.addCallback(messageIdFuture, new ApiFutureCallback<AppendRowsResponse>() {
242+
* ApiFuture<AppendRowsResponse> future = writer.append(rows, 0);
243+
* ApiFutures.addCallback(future, new ApiFutureCallback<AppendRowsResponse>() {
235244
* public void onSuccess(AppendRowsResponse response) {
236245
* if (!response.hasError()) {
237246
* System.out.println("written with offset: " + response.getAppendResult().getOffset());
@@ -247,7 +256,7 @@ public void run(Throwable finalStatus) {
247256
* }</pre>
248257
*
249258
* @param rows the rows in serialized format to write to BigQuery.
250-
* @param offset the offset of the first row.
259+
* @param offset the offset of the first row. Provide -1 to write at the current end of stream.
251260
* @return the append response wrapped in a future.
252261
*/
253262
public ApiFuture<AppendRowsResponse> append(ProtoRows rows, long offset) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private AppendRowsResponse createAppendResponseWithError(Status.Code code, Strin
131131
}
132132

133133
private ApiFuture<AppendRowsResponse> sendTestMessage(StreamWriter writer, String[] messages) {
134-
return writer.append(createProtoRows(messages), -1);
134+
return writer.append(createProtoRows(messages));
135135
}
136136

137137
private ApiFuture<AppendRowsResponse> sendTestMessage(

0 commit comments

Comments
 (0)