Skip to content

impl(bigquery): add attach_job method to query client - #6338

Merged
haphungw merged 3 commits into
googleapis:mainfrom
haphungw:feat-bq-attach-job-fix
Aug 12, 2026
Merged

impl(bigquery): add attach_job method to query client#6338
haphungw merged 3 commits into
googleapis:mainfrom
haphungw:feat-bq-attach-job-fix

Conversation

@haphungw

Copy link
Copy Markdown
Contributor

Add BigQuery::attach_job to bind an existing out-of-process query job reference (JobReference) to a high-level Query handle without re-submitting SQL.

When #6295 was originally merged, it conflicted with #6317 (which was merged before and refactored Query struct fields to use QueryCreationMetadata). This caused post-merge build failures because attach_job referenced the old struct fields.

This PR re-adds the changes with fixes to be compatible with QueryCreationMetadata.

@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the BigQuery API. label Aug 11, 2026
@haphungw
haphungw marked this pull request as ready for review August 11, 2026 20:42
@haphungw
haphungw requested a review from a team as a code owner August 11, 2026 20:42

@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 introduces an attach_job method to the BigQuery client, allowing users to bind an existing out-of-process query job reference to a high-level Query handle. The feedback focuses on the removal of the MissingProjectId error variant in favor of a generic InvalidArgument variant. The reviewer notes that this is a breaking change and violates the repository style guide regarding meaningful error distinctions. They recommend retaining MissingProjectId to preserve backward compatibility, avoid unnecessary string allocations, and keep error handling structured.

Comment thread src/bigquery/src/error.rs Outdated
Comment on lines +24 to +26
/// An invalid argument was provided (e.g. missing job ID or project ID).
#[error("invalid argument: {0}")]
InvalidArgument(String),

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.

medium

Removing the MissingProjectId variant from the public QueryError enum is a breaking change for existing clients that match on this error. Additionally, the repository style guide states that custom error types should imply meaningful distinctions for the user and error variants should be actionable. Replacing a specific error with a generic InvalidArgument(String) makes it harder to programmatically handle a missing project ID. We should keep MissingProjectId and add InvalidArgument(String) as a new variant.

Suggested change
/// An invalid argument was provided (e.g. missing job ID or project ID).
#[error("invalid argument: {0}")]
InvalidArgument(String),
/// The project ID was not provided or could not be determined.
#[error("no project ID was provided")]
MissingProjectId,
/// An invalid argument was provided (e.g. missing job ID).
#[error("invalid argument: {0}")]
InvalidArgument(String),
References
  1. The repository style guide states that custom error types should imply meaningful distinctions for the user and error variants should be actionable. (link)

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.

I'm still on a fence on this subject and was going to bring it on the API review, but the bot brought this argument and similar to @suzmue said, having a generic InvalidArgument is not really useful and I'm leaning more towards having MissingProjectId and MissingJobId, because they are actionable in specific ways. The problem is that later if we have another required argument, are we going to keep adding MissingX ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's fair.

Now that we no longer handle job_id, it's not a problem for this PR anymore, but I think we should still consider this for future cases?

Comment thread src/bigquery/src/client.rs
Comment thread src/bigquery/src/query/run_query.rs Outdated
Comment thread src/bigquery/src/query/run_query.rs Outdated
Comment thread src/bigquery/src/client.rs Outdated
Comment thread src/bigquery/src/client.rs
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.11%. Comparing base (06b4294) to head (c311945).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6338      +/-   ##
==========================================
+ Coverage   96.10%   96.11%   +0.01%     
==========================================
  Files         282      282              
  Lines       73304    73443     +139     
==========================================
+ Hits        70449    70591     +142     
+ Misses       2855     2852       -3     

☔ 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.

Comment thread src/bigquery/src/client.rs Outdated
@haphungw
haphungw force-pushed the feat-bq-attach-job-fix branch 5 times, most recently from e9deca5 to 52dde42 Compare August 11, 2026 21:37
@haphungw
haphungw force-pushed the feat-bq-attach-job-fix branch from 52dde42 to c311945 Compare August 11, 2026 21:38
@haphungw
haphungw merged commit e1a909c into googleapis:main Aug 12, 2026
41 checks passed
@haphungw
haphungw deleted the feat-bq-attach-job-fix branch August 12, 2026 14:34
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