Skip to content

Conversation

@mburuian6
Copy link
Contributor

…8419)

Fixes #18419


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @mburuian6, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the error reporting for BigQuery load jobs by logging more specific details about the BigQuery error that caused the job to fail. This change aims to improve the diagnostic capabilities when encountering persistent load job failures, providing clearer insights into the underlying problems.

Highlights

  • Enhanced Error Logging: Introduced detailed logging for BigQuery load job failures, specifically capturing the BigQuery errorResult and the root cause error from the errors array.
  • Improved Debuggability: The new logging provides more specific information when a BigQuery load job fails after all retries, aiding in quicker identification and resolution of issues.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2025

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2025

Assigning reviewers:

R: @robertwb for label java.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@derrickaw
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds logging for BigQuery load job failures, which is a great improvement for debugging. The new logic correctly identifies the final error and the causative error from the job status.

My review focuses on improving the robustness and efficiency of the new logging method. I've suggested a revision to handle potential null values safely, avoid redundant method calls, and refine the log message formatting. These changes will make the error logging more reliable.

Comment on lines +287 to +300
void logBigQueryError(@Nullable Job job) {
if (job == null || !parseStatus(job).equals(Status.FAILED)) {
return;
}

List<ErrorProto> jobErrors = job.getStatus().getErrors();
String finalError = job.getStatus().getErrorResult().getMessage();
String causativeError =
jobErrors != null && !jobErrors.isEmpty()
? String.format(" due to: %s", jobErrors.get(jobErrors.size() - 1).getMessage())
: "";

LOG.error(String.format("BigQuery Error : %s %s", finalError, causativeError));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new logBigQueryError method has a few issues that could lead to runtime errors and inefficient execution:

  • Potential NullPointerException: job.getStatus() can return null, which is not handled. The call to parseStatus(job) is unsafe as parseStatus itself doesn't handle a null JobStatus. Even if it were safe, subsequent calls to job.getStatus() within this method are also not null-safe.
  • Inefficiency: job.getStatus() is called multiple times. It's better to call it once and store the result in a local variable.
  • Incomplete error handling: The logic assumes job.getStatus().getErrorResult() is not null. If a job fails with errors in the errors list but errorResult is null, this method would fail instead of logging the available error information.
  • Log message formatting: The use of String.format("... %s %s", ...) can result in extraneous spaces in the log message.

Here is a revised implementation that addresses these points, making the method safer, more efficient, and more robust.

    void logBigQueryError(@Nullable Job job) {
      if (job == null) {
        return;
      }
      final JobStatus status = job.getStatus();
      if (status == null
          || (status.getErrorResult() == null
              && (status.getErrors() == null || status.getErrors().isEmpty()))) {
        return;
      }

      String finalError;
      if (status.getErrorResult() != null && status.getErrorResult().getMessage() != null) {
        finalError = status.getErrorResult().getMessage();
      } else {
        finalError = "Job failed with an unknown error";
      }

      List<ErrorProto> jobErrors = status.getErrors();
      String causativeErrorDetails = "";
      if (jobErrors != null && !jobErrors.isEmpty()) {
        causativeErrorDetails = " due to: " + jobErrors.get(jobErrors.size() - 1).getMessage();
      }

      LOG.error(String.format("BigQuery Error : %s%s", finalError, causativeErrorDetails));
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null issues called out here aren't real, these methods all return non-null results.

The efficiency piece doesn't matter in the failure condition, and the formatting should be fine

@derrickaw
Copy link
Collaborator

Can we also add a test here? thanks

Copy link
Contributor

@damccorm damccorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines +287 to +300
void logBigQueryError(@Nullable Job job) {
if (job == null || !parseStatus(job).equals(Status.FAILED)) {
return;
}

List<ErrorProto> jobErrors = job.getStatus().getErrors();
String finalError = job.getStatus().getErrorResult().getMessage();
String causativeError =
jobErrors != null && !jobErrors.isEmpty()
? String.format(" due to: %s", jobErrors.get(jobErrors.size() - 1).getMessage())
: "";

LOG.error(String.format("BigQuery Error : %s %s", finalError, causativeError));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null issues called out here aren't real, these methods all return non-null results.

The efficiency piece doesn't matter in the failure condition, and the formatting should be fine

@damccorm
Copy link
Contributor

damccorm commented Sep 8, 2025

LGTM, but agreed with Derrick's comment, adding a test is a good idea

@mburuian6
Copy link
Contributor Author

@damccorm @derrickaw I think this is the test for the failure message , I'd probably have to change the FakeJobService to give all failed jobs a list of error protos that include the errorResult.

@damccorm
Copy link
Contributor

damccorm commented Sep 8, 2025

Yeah, I think that is right. Looking at that test, it does look like we at least execute this code path, which seems probably good enough. Testing log messages is otherwise painful. So I think we can just take this as is

@damccorm damccorm merged commit ed383fa into apache:master Sep 8, 2025
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log the reason for failure for BigQuery jobs

3 participants