Skip to content

[Python] Support BigQuery job labels to WriteToBigQuery - #41470

Open
KyungmoKu wants to merge 2 commits into
apache:masterfrom
KyungmoKu:bigquery-write-job-labels-upstream
Open

KyungmoKu wants to merge 2 commits into
apache:masterfrom
KyungmoKu:bigquery-write-job-labels-upstream

Conversation

@KyungmoKu

@KyungmoKu KyungmoKu commented Nov 19, 2026 •

Copy link
Copy Markdown

Python ReadFromBigQuery accepts BigQuery job labels, but WriteToBigQuery does not.

This adds the same bigquery_job_labels option for load, copy, and schema-update jobs created by WriteToBigQuery, with method FILE_LOADS.

WriteToBigQuery(
    table="project:dataset.table",
    method=WriteToBigQuery.Method.FILE_LOADS,
    bigquery_job_labels={"environment": "production"},
)

Notes

Validation

(1) Ran this version locally against real BigQuery and confirmed the job labels work.

(2) From sdks/python, after the Python development setup:

pytest -q apache_beam/io/gcp/bigquery_test.py apache_beam/io/gcp/bigquery_file_loads_test.py -k "bigquery_job_labels or to_from_runner_api"

@github-actions github-actions Bot added python io gcp size/m M: 50-249 lines changed labels Nov 19, 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 bigquery_job_labels support to Python's WriteToBigQuery transform for FILE_LOADS, propagating user-provided labels alongside Beam's metadata labels to load, copy, and schema-update BigQuery jobs. It also validates that non-empty bigquery_job_labels are rejected for write methods that do not create BigQuery jobs (STREAMING_INSERTS and STORAGE_WRITE_API), and includes unit tests covering Runner API serialization, method validation, and label propagation across all job types.

🔍 General Feedback

  • Passing self.bigquery_job_labels.copy() to add_additional_bq_job_labels() in UpdateDestinationSchema, TriggerCopyJobs, and TriggerLoadJobs cleanly avoids mutating the shared dictionary on the DoFn instances.
  • The implementation and unit tests are thorough, well-structured, and ready to merge.

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

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label python.
Backup reviewer: claudevdm (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).

@KyungmoKu

Copy link
Copy Markdown
Author

cc @claudevdm @shunping

@KyungmoKu KyungmoKu changed the title Add BigQuery job labels to Python WriteToBigQuery [Python] Support BigQuery job labels to WriteToBigQuery Nov 23, 2026

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

Thanks - this LGTM, just had one small comment

Comment thread CHANGES.md Outdated
Comment on lines 105 to 106

* X feature added (Java/Python) ([#X](https://github.com/apache/beam/issues/X)).

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.

Nit: please remove the trailing space and the placeholder item

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

addressed in a9081ce .

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.67%. Comparing base (5b9b188) to head (308d6bc).
⚠️ Report is 109 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41470      +/-   ##
============================================
- Coverage     58.77%   58.67%   -0.11%     
  Complexity     2292     2292              
============================================
  Files          1134     1134              
  Lines        170223   170230       +7     
  Branches       1487     1487              
============================================
- Hits         100049    99878     -171     
- Misses        67630    67808     +178     
  Partials       2544     2544              
Flag Coverage Δ
python 80.65% <100.00%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KyungmoKu

Copy link
Copy Markdown
Author

Thanks for the review, @damccorm .

My org's internal review of this contribution may take a little longer over Thanksgiving, but I’ll follow up as soon as it’s complete.

Appreciate if this could be hold.

Co-authored-by: Codex gpt-6.1-sol <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants