Skip to content

Support BigQuery load job reservations in Java BigQueryIO - #41329

Merged
ahmedabu98 merged 6 commits into
apache:masterfrom
paragpratim:feat/add-bq-reservation-job-config
Dec 3, 2026
Merged

ahmedabu98 merged 6 commits into
apache:masterfrom
paragpratim:feat/add-bq-reservation-job-config

Conversation

@paragpratim

@paragpratim paragpratim commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Adds an optional reservation setting to Java BigQueryIO.Write for FILE_LOADS. This allows load jobs to specify a reservation managed in another project instead of relying only on the job project's assignment.

The reservation is passed to regular, temporary-table, and schema-update load jobs. It supports ValueProvider for runtime configuration.

Existing behavior is unchanged when no reservation is specified.

withLoadJobProjectId continues to control the project in which the load job is created; the reservation setting does not change it.

Fixes #41212

Validation

  • Reservation and file-load unit tests: passed (16 passed, 9 skipped).
  • Java formatting and Checkstyle: passed.
  • Live BigQuery test: the load job used the specified reservation. The Dataflow test pipeline uses separate job and reservation projects.

@github-actions github-actions Bot added java io gcp size/m M: 50-249 lines changed labels Nov 14, 2026

@github-actions github-actions 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.

📋 Review Summary

This PR adds support for specifying a BigQuery reservation on FILE_LOADS jobs (BigQueryIO.Write.withLoadJobReservation), propagating the setting through BatchLoads, WriteTables, UpdateSchemaDestination, BigQueryServices, and BigQueryIOTranslation with solid unit test coverage.

🔍 General Feedback

  • Runtime ValueProvider handling for optional template parameters: When withLoadJobReservation(ValueProvider<String>) is wired in a pipeline template, the ValueProvider instance itself is non-null at construction time, but loadJobReservation.get() will return null (or "") at runtime when the optional parameter is not supplied by the user. WriteTables and UpdateSchemaDestination should treat a null/empty runtime value as unset rather than throwing IllegalArgumentException, matching how loadJobProjectId and customGcsTempLocation behave.
  • Delegation in BigQueryServicesImpl and FakeJobService: Existing startLoadJob overloads can delegate to the new reservation-aware overloads with null to eliminate duplicate job construction logic and allow FakeJobService to support unreserved stream load jobs as well.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added size/l L: 250-999 lines changed and removed size/m M: 50-249 lines changed labels Nov 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @ahmedabu98 for label java.
Backup reviewer: Abacn (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

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

@paragpratim

Copy link
Copy Markdown
Contributor Author

Hi @ahmedabu98, when you have a chance, could you please take a look at this PR? The automated review feedback has been addressed, and the targeted tests pass. Thank you!

@paragpratim

Copy link
Copy Markdown
Contributor Author

Hi @Abacn, since @ahmedabu98 might be busy, could you please take a look at this PR when you have a moment?

The automated review feedback has been addressed and all targeted tests are passing.

Thanks!

@ahmedabu98 ahmedabu98 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.

The changes so far look good, but I think it's a little incomplete.

We should pass the reservation to the copy-job path as well (should go through WriteRename and BigQueryServices#startCopyJob(...). And add relevant tests please

@paragpratim

Copy link
Copy Markdown
Contributor Author

We should pass the reservation to the copy-job path as well (should go through WriteRename and BigQueryServices#startCopyJob(...). And add relevant tests please

Thats a good observation. I have made the changes but before committing would like to share the observations

  • COPY jobs accepts the explicit slot reservation but does not use them and depend on them. Also I see no slot usage in copy jobs. I forced a copy job with FILE_LOAD using .withMaxFilesPerPartition(1)
    • without .withLoadJobReservation : LOAD jobs fails with error - However, only jobs that run on a reservation with the "ENTERPRISE_PLUS" edition can modify or write to failover datasets. Please also make sure that the job that is writing to the failover dataset is running in the current primary location. But the COPY job is successful. None of them has "reservation": in the job metadata.
    • with .withLoadJobReservation : Both LOAD jobs and COPY jobs has the mentioned "reservation": in the metadata and both success. But copy job does not show any slot usage.

So it looks like adding reservation in the copy job does not has any impact. Even on a dataset with ENTERPRISE_PLUS reservation , COPY jobs works without explicit mention of reservation in the job definition.

Also I was looking into this documentation - https://docs.cloud.google.com/bigquery/docs/reservations-workload-management#reservation_assignments which does not explicitly mention COPY job.

Do you think we still should propagate the reservation in the COPY job definition as well ?

@ahmedabu98

Copy link
Copy Markdown
Contributor

I see, that's rather interesting. Thanks for trying it out.

I'll leave it up to you. I'm okay with leaving it out for now, although if BQ decides to add reservation support to copy jobs, we'll have to add it back in the future.

Either way I think we should add a small mention in javadoc somewhere about the behavior of reservations on copy jobs

@paragpratim

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback!

although if BQ decides to add reservation support to copy jobs, we'll have to add it back in the future.

I decided to pass the reservation to copy jobs as well. I think it make sense to add this. COPY JOB API also supports this reservation parameter , so it's consistent with the load job. and Indeed if in future BQ changes the behaviour then this is already covered.

I’ve also added small note in the Javadoc to mention that the reservation is passed to copy jobs and that BigQuery’s handling may differ from load jobs.

@ahmedabu98

Copy link
Copy Markdown
Contributor

Awesome thank you! merging now

@ahmedabu98
ahmedabu98 merged commit 7e87ced into apache:master Dec 3, 2026
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.

[Feature Request]: Support BigQuery reservation for Java BigQueryIO FILE_LOADS

2 participants