Skip to content

Commit b9f2055

Browse files
Capture full response context to provide complete error information (#24416)
* capturing the full context failures to provide full picture of what has failed in the insert. * fix checks
1 parent 0305267 commit b9f2055

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StorageApiWriteUnshardedRecords.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.concurrent.Executors;
4242
import java.util.concurrent.TimeUnit;
4343
import java.util.stream.Collectors;
44+
import java.util.stream.StreamSupport;
4445
import org.apache.beam.sdk.coders.Coder;
4546
import org.apache.beam.sdk.coders.KvCoder;
4647
import org.apache.beam.sdk.coders.StringUtf8Coder;
@@ -451,8 +452,6 @@ long flush(
451452
DynamicMessage.parseFrom(
452453
Preconditions.checkStateNotNull(appendClientInfo).descriptor,
453454
protoBytes));
454-
new BigQueryStorageApiInsertError(
455-
failedRow, error.getRowIndexToErrorMessage().get(failedIndex));
456455
failedRowsReceiver.output(
457456
new BigQueryStorageApiInsertError(
458457
failedRow, error.getRowIndexToErrorMessage().get(failedIndex)));
@@ -488,7 +487,7 @@ long flush(
488487
"Append to stream {} by client #{} failed with error, operations will be retried. Details: {}",
489488
streamName,
490489
clientNumber,
491-
retrieveErrorDetails(failedContext));
490+
retrieveErrorDetails(contexts));
492491
invalidateWriteStream();
493492
appendFailures.inc();
494493
return RetryType.RETRY_ALL_OPERATIONS;
@@ -501,13 +500,13 @@ long flush(
501500
return inserts.getSerializedRowsCount();
502501
}
503502

504-
String retrieveErrorDetails(AppendRowsContext failedContext) {
505-
return (failedContext.getError() != null)
506-
? Arrays.stream(
507-
Preconditions.checkStateNotNull(failedContext.getError()).getStackTrace())
508-
.map(StackTraceElement::toString)
509-
.collect(Collectors.joining("\n"))
510-
: "no execption";
503+
String retrieveErrorDetails(Iterable<AppendRowsContext> failedContext) {
504+
return StreamSupport.stream(failedContext.spliterator(), false)
505+
.<@Nullable Throwable>map(AppendRowsContext::getError)
506+
.filter(err -> err != null)
507+
.flatMap(thrw -> Arrays.stream(Preconditions.checkStateNotNull(thrw).getStackTrace()))
508+
.map(StackTraceElement::toString)
509+
.collect(Collectors.joining("\n"));
511510
}
512511
}
513512

0 commit comments

Comments
 (0)