Skip to content

Commit

Permalink
docs(samples): Check for error from BatchCommitWriteStreams (#940)
Browse files Browse the repository at this point in the history
If the returned BatchCommitWriteStreamsResponse does not have a commit time, it means an error occurred.
  • Loading branch information
VeronicaWasson authored Mar 25, 2021
1 parent 4442583 commit ab3c145
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.cloud.bigquery.storage.v1beta2.CreateWriteStreamRequest;
import com.google.cloud.bigquery.storage.v1beta2.FinalizeWriteStreamResponse;
import com.google.cloud.bigquery.storage.v1beta2.JsonStreamWriter;
import com.google.cloud.bigquery.storage.v1beta2.StorageError;
import com.google.cloud.bigquery.storage.v1beta2.TableName;
import com.google.cloud.bigquery.storage.v1beta2.WriteStream;
import com.google.protobuf.Descriptors.DescriptorValidationException;
Expand Down Expand Up @@ -90,6 +91,13 @@ public static void writePendingStream(String projectId, String datasetName, Stri
.build();
BatchCommitWriteStreamsResponse commitResponse =
client.batchCommitWriteStreams(commitRequest);
// If the response does not have a commit time, it means the commit operation failed.
if (commitResponse.hasCommitTime() == false) {
for (StorageError err : commitResponse.getStreamErrorsList()) {
System.out.println(err.getErrorMessage());
}
throw new RuntimeException("Error committing the streams");
}
System.out.println("Appended and committed records successfully.");
} catch (ExecutionException e) {
// If the wrapped exception is a StatusRuntimeException, check the state of the operation.
Expand Down

0 comments on commit ab3c145

Please sign in to comment.