Skip to content

Revert "[Python] Optimize BigQuery copy jobs in file loads using multi-source copy"#39106

Merged
shunping merged 2 commits into
apache:masterfrom
shunping:revert-pr-38983
Jun 25, 2026
Merged

Revert "[Python] Optimize BigQuery copy jobs in file loads using multi-source copy"#39106
shunping merged 2 commits into
apache:masterfrom
shunping:revert-pr-38983

Conversation

@shunping

@shunping shunping commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Reverting #38983 since it is causing some postcommit test failure.

See #30513 (comment) for detail.

@shunping

Copy link
Copy Markdown
Collaborator Author

r: @stankiewicz @Amar3tto

@shunping shunping marked this pull request as ready for review June 25, 2026 18:14
@shunping shunping requested a review from Amar3tto June 25, 2026 18:15
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 serves as a corrective measure to address stability issues in post-commit tests caused by the recent implementation of BigQuery copy job batching. By reverting the batching logic and refactoring the copy job trigger mechanism, the changes aim to restore the reliability of BigQuery file load operations while maintaining correct write disposition behavior.

Highlights

New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 counterproductive. 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.

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.

@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 refactors the BigQuery file loads pipeline in the Python SDK to trigger copy jobs individually rather than chunking them into batches. It removes the batching logic and simplifies the copy job configuration. The review feedback highlights three important issues: first, grouping temporary tables by tableId instead of their full hashable destination can cause key collisions across different datasets or projects; second, instantiating BigQueryWrapper inline on every element is inefficient and should be replaced with the existing reusable instance; and third, removing the guard check before appending partitions could lead to empty partitions being created.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +1184 to +1189
finished_temp_tables_load_job_ids_pc | beam.MapTuple(
lambda destination, job_reference: (
bigquery_tools.get_hashable_destination(destination),
bigquery_tools.parse_table_reference(destination).tableId,
(destination, job_reference)))
| beam.GroupByKey()
| beam.MapTuple(lambda dest, batch: list(batch)))
| beam.MapTuple(lambda tableId, batch: list(batch)))

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.

high

Using only tableId as the grouping key can cause collisions if the pipeline writes to multiple datasets or projects that contain tables with the same name (e.g., dataset_A.my_table and dataset_B.my_table). Using get_hashable_destination ensures that the full destination (project, dataset, and table) is used as the key, preventing incorrect grouping and potential data corruption.

Suggested change
finished_temp_tables_load_job_ids_pc | beam.MapTuple(
lambda destination, job_reference: (
bigquery_tools.get_hashable_destination(destination),
bigquery_tools.parse_table_reference(destination).tableId,
(destination, job_reference)))
| beam.GroupByKey()
| beam.MapTuple(lambda dest, batch: list(batch)))
| beam.MapTuple(lambda tableId, batch: list(batch)))
finished_temp_tables_load_job_ids_pc | beam.MapTuple(
lambda destination, job_reference: (
bigquery_tools.get_hashable_destination(destination),
(destination, job_reference)))
| beam.GroupByKey()
| beam.MapTuple(lambda dest, batch: list(batch)))

try:
schema = bigquery_tools.table_schema_to_dict(
self.bq_wrapper.get_table(
bigquery_tools.BigQueryWrapper().get_table(

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

Instantiating BigQueryWrapper inline on every element/iteration inside process is inefficient because it initializes HTTP clients and credentials repeatedly. It is better to reuse the existing self.bq_wrapper instance.

Suggested change
bigquery_tools.BigQueryWrapper().get_table(
self.bq_wrapper.get_table(

else:
if latest_partition.files:
partitions.append(latest_partition.files)
partitions.append(latest_partition.files)

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

Without checking if latest_partition.files is non-empty, an empty list could be appended to partitions if the first file cannot be accepted. Adding a guard prevents empty partitions from being created.

        if latest_partition.files:
          partitions.append(latest_partition.files)

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@shunping shunping changed the title Revert pr 38983 Revert "[Python] Optimize BigQuery copy jobs in file loads using multi-source copy" Jun 25, 2026
@Amar3tto

Copy link
Copy Markdown
Collaborator

Waiting for checks

@shunping shunping merged commit eef26ca into apache:master Jun 25, 2026
118 of 119 checks passed
@shunping

Copy link
Copy Markdown
Collaborator Author

All tests passed.

shunping added a commit to shunping/beam that referenced this pull request Jun 25, 2026
…i-source copy" (apache#39106)

* Revert "[Python] Optimize BigQuery copy jobs in file loads using multi-source copy (apache#38983)"

This reverts commit 8e4ea73.

* Trigger postcommit test.
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.

3 participants