Skip to content
Permalink
Browse files
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> ☕️
  • Loading branch information
jphalip committed Dec 23, 2021
1 parent e47ac79 commit cb8b0ad25fbf07c3509b3d94244a999b9cb90e54
@@ -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<AppendRowsResponse> returns an AppendRowsResponse message wrapped in an
@@ -92,7 +93,8 @@ public ApiFuture<AppendRowsResponse> 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
@@ -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.
*
* <p>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<AppendRowsResponse> append(ProtoRows rows) {
return append(rows, -1);
}

/**
* Schedules the writing of rows at given offset.
*
* <p>Example of writing rows with specific offset.
*
* <pre>{@code
* AppendRowsRequest message;
* ApiFuture<AppendRowsResponse> messageIdFuture = writer.append(message);
* ApiFutures.addCallback(messageIdFuture, new ApiFutureCallback<AppendRowsResponse>() {
* ApiFuture<AppendRowsResponse> future = writer.append(rows, 0);
* ApiFutures.addCallback(future, new ApiFutureCallback<AppendRowsResponse>() {
* 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) {
* }</pre>
*
* @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<AppendRowsResponse> append(ProtoRows rows, long offset) {
@@ -131,7 +131,7 @@ private AppendRowsResponse createAppendResponseWithError(Status.Code code, Strin
}

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

private ApiFuture<AppendRowsResponse> sendTestMessage(

0 comments on commit cb8b0ad

Please sign in to comment.