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

Commit ab3c145

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.
1 parent 4442583 commit ab3c145

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.cloud.bigquery.storage.v1beta2.CreateWriteStreamRequest;
2626
import com.google.cloud.bigquery.storage.v1beta2.FinalizeWriteStreamResponse;
2727
import com.google.cloud.bigquery.storage.v1beta2.JsonStreamWriter;
28+
import com.google.cloud.bigquery.storage.v1beta2.StorageError;
2829
import com.google.cloud.bigquery.storage.v1beta2.TableName;
2930
import com.google.cloud.bigquery.storage.v1beta2.WriteStream;
3031
import com.google.protobuf.Descriptors.DescriptorValidationException;
@@ -90,6 +91,13 @@ public static void writePendingStream(String projectId, String datasetName, Stri
9091
.build();
9192
BatchCommitWriteStreamsResponse commitResponse =
9293
client.batchCommitWriteStreams(commitRequest);
94+
// If the response does not have a commit time, it means the commit operation failed.
95+
if (commitResponse.hasCommitTime() == false) {
96+
for (StorageError err : commitResponse.getStreamErrorsList()) {
97+
System.out.println(err.getErrorMessage());
98+
}
99+
throw new RuntimeException("Error committing the streams");
100+
}
93101
System.out.println("Appended and committed records successfully.");
94102
} catch (ExecutionException e) {
95103
// If the wrapped exception is a StatusRuntimeException, check the state of the operation.

0 commit comments

Comments
 (0)