Skip to content

feat(bigquery): handle duplicate job error with jobs.query - #6801

Open
alvarowolfx wants to merge 2 commits into
googleapis:mainfrom
alvarowolfx:feat-bq-retry-409-jobs-query
Open

alvarowolfx wants to merge 2 commits into
googleapis:mainfrom
alvarowolfx:feat-bq-retry-409-jobs-query

Conversation

@alvarowolfx

Copy link
Copy Markdown
Contributor

A transport/io error can happen after query was submitted via jobs.query and finished execution, and RPC level retries might try to re-run it with same request ID. But request ID only dedups in-flight queries, this causes a 409 error. Instead of re running the query, we can connect to the existing one to avoid extra billing.

Towards #6218 #6717

@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the BigQuery API. label Sep 14, 2026
@alvarowolfx

Copy link
Copy Markdown
Contributor Author

The debatable aspect here is that 409 errors on jobs.query don't have a structured way to provide job ID, so we have to do some error message parsing. Thoughts @dbolduc ?

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

Copy link
Copy Markdown
Contributor

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 enhances BigQuery query execution by handling duplicate job errors (HTTP 409). When a duplicate job is detected, the system now parses the job reference from the error message and attempts to attach to the existing job. The review feedback highlights that the current parsing logic for duplicate job references is fragile when encountering domain-scoped project IDs without a location, and suggests a more robust parsing implementation along with corresponding unit test updates.

Comment thread src/bigquery/src/query/execution.rs Outdated
Comment thread src/bigquery/src/query/execution.rs
@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.72611% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.02%. Comparing base (8fb991a) to head (261268b).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/bigquery/src/query/execution.rs 98.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6801      +/-   ##
==========================================
- Coverage   97.03%   97.02%   -0.01%     
==========================================
  Files         326      326              
  Lines      107511   107659     +148     
==========================================
+ Hits       104322   104459     +137     
- Misses       3189     3200      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbolduc

dbolduc commented Sep 14, 2026

Copy link
Copy Markdown
Member

The debatable aspect here is that 409 errors on jobs.query don't have a structured way to provide job ID, so we have to do some error message parsing. Thoughts @dbolduc ?

Error parsing is definitely a smell and brittle, but sometimes it must be done. We can open an issue / feature request with the service team to make it a structured error and reference that in the code.

@alvarowolfx
alvarowolfx marked this pull request as ready for review September 15, 2026 16:04
@alvarowolfx
alvarowolfx requested a review from a team as a code owner September 15, 2026 16:04

@dbolduc dbolduc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. I like that we are making the effort to retry these.

Comment on lines +216 to +219
let existing_job = match get {
Some(get) => Box::pin(get.send()).await.ok(),
None => None,
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this looks like an .and_then()

Comment on lines +221 to +222
// This error names the job and, unlike a `jobs.get`
// failure, never makes the retry loop reissue the query.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: there are a few ways to end up here. Should it be like?

// We were unable to parse the job in the error message, or successfully send a
// `GetJob` RPC. Return the original error message. 

Or: // Oh well, we tried. 😛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants