Skip to content
Permalink
Browse files
docs(samples): Check for error from BatchCommitWriteStreams (#940)
If the returned BatchCommitWriteStreamsResponse does not have a commit time, it means an error occurred.
  • Loading branch information
VeronicaWasson committed Mar 25, 2021
1 parent 4442583 commit ab3c1453d3c1fb627e773d0e7ca4ec991f8d38b7
Showing with 8 additions and 0 deletions.
  1. +8 −0 samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
@@ -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;
@@ -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.

0 comments on commit ab3c145

Please sign in to comment.