Skip to content

Commit ed383fa

Browse files
authored
Logs the BigQuery error that caused the load job failure (resolves #1… (apache#36068)
* Logs the BigQuery error that caused the load job failure (resolves apache#18419) * Checks that the BigQuery root cause message to be logged is not empty (resolves apache#18419)
1 parent a351c88 commit ed383fa

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

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

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.api.client.util.Sleeper;
2626
import com.google.api.services.bigquery.model.Clustering;
2727
import com.google.api.services.bigquery.model.Dataset;
28+
import com.google.api.services.bigquery.model.ErrorProto;
2829
import com.google.api.services.bigquery.model.Job;
2930
import com.google.api.services.bigquery.model.JobReference;
3031
import com.google.api.services.bigquery.model.JobStatus;
@@ -205,6 +206,7 @@ static class PendingJob implements Serializable {
205206
void runJob() throws IOException {
206207
++currentAttempt;
207208
if (!shouldRetry()) {
209+
logBigQueryError(lastJobAttempted);
208210
throw new RuntimeException(
209211
String.format(
210212
"Failed to create job with prefix %s, "
@@ -281,6 +283,21 @@ boolean pollJob() throws IOException {
281283
boolean shouldRetry() {
282284
return currentAttempt < maxRetries + 1;
283285
}
286+
287+
void logBigQueryError(@Nullable Job job) {
288+
if (job == null || !parseStatus(job).equals(Status.FAILED)) {
289+
return;
290+
}
291+
292+
List<ErrorProto> jobErrors = job.getStatus().getErrors();
293+
String finalError = job.getStatus().getErrorResult().getMessage();
294+
String causativeError =
295+
jobErrors != null && !jobErrors.isEmpty()
296+
? String.format(" due to: %s", jobErrors.get(jobErrors.size() - 1).getMessage())
297+
: "";
298+
299+
LOG.error(String.format("BigQuery Error : %s %s", finalError, causativeError));
300+
}
284301
}
285302

286303
static class RetryJobId implements Serializable {

0 commit comments

Comments
 (0)