Skip to content

[Python] Ad BigQuery Change History source.#37724

Open
claudevdm wants to merge 5 commits intoapache:masterfrom
claudevdm:bq-cdc-io
Open

[Python] Ad BigQuery Change History source.#37724
claudevdm wants to merge 5 commits intoapache:masterfrom
claudevdm:bq-cdc-io

Conversation

@claudevdm
Copy link
Collaborator

Please add a meaningful description for your change here


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@gemini-code-assist
Copy link
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 introduces a new PTransform for Apache Beam's Python SDK, enabling streaming Change Data Capture (CDC) from Google BigQuery. It allows users to continuously ingest changes from BigQuery tables using either the APPENDS() or CHANGES() SQL functions. The design focuses on robust watermark handling, efficient data retrieval via the BigQuery Storage Read API, and automatic cleanup of temporary resources, providing a reliable and scalable solution for real-time data synchronization with BigQuery.

Highlights

  • New BigQuery CDC PTransform: Introduced a new ReadBigQueryChangeHistory PTransform in the Python SDK, enabling streaming Change Data Capture (CDC) from Google BigQuery.
  • Support for APPENDS/CHANGES functions: The PTransform is designed to continuously poll BigQuery's APPENDS() or CHANGES() SQL functions to capture data modifications.
  • Modular Architecture: The implementation is structured into distinct stages: a polling Splittable DoFn (SDF) for generating query ranges, an _ExecuteQueryFn for running BQ queries and writing results to temporary tables, an SDF for reading from these temporary tables via the Storage Read API with dynamic splitting, and a stateful _CleanupTempTablesFn for managing and deleting temporary tables.
  • Advanced Watermark Management: Custom watermark estimators (_PollWatermarkEstimator, _CDCWatermarkEstimatorProvider) are implemented to accurately track watermarks based on poll cursors and event timestamps, ensuring correct processing order.
  • Automated Temporary Resource Management: The system automatically creates temporary datasets with a 24-hour expiration policy for robustness and ensures cleanup of temporary tables after data has been processed.
  • Comprehensive Testing: New integration tests (bigquery_change_history_it_test.py) validate the PTransform against a real BigQuery environment, and unit tests (bigquery_change_history_test.py) cover query building logic, range computation, and input validation.

🧠 New Feature in Public Preview: You can now enable Memory 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.

Changelog
  • sdks/python/apache_beam/io/gcp/bigquery_change_history.py
    • Added ReadBigQueryChangeHistory PTransform for BigQuery CDC.
    • Implemented polling SDF (_PollChangeHistoryFn) for query range generation.
    • Introduced _ExecuteQueryFn to run BQ queries and manage temporary tables.
    • Developed _ReadStorageStreamsSDF for reading data from temporary tables using the BigQuery Storage Read API.
    • Included _CleanupTempTablesFn for stateful cleanup of temporary BigQuery tables.
    • Defined helper functions like build_changes_query and compute_ranges for SQL generation and time range management.
    • Added custom watermark estimators (_PollWatermarkEstimator, _CDCWatermarkEstimatorProvider) for accurate watermark tracking.
  • sdks/python/apache_beam/io/gcp/bigquery_change_history_it_test.py
    • Added integration tests for ReadBigQueryChangeHistory and its internal components.
    • Included tests for _CleanupTempTablesFn, _ReadStorageStreamsSDF, _PollChangeHistoryFn, and _ExecuteQueryFn.
    • Implemented an end-to-end test for the public API.
  • sdks/python/apache_beam/io/gcp/bigquery_change_history_test.py
    • Added unit tests for build_changes_query, compute_ranges, _table_key, and ReadBigQueryChangeHistory validation.
Activity
  • The pull request introduces a new feature and associated tests, with no explicit comments or reviews mentioned in the provided context.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@claudevdm
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

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

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 a new BigQuery CDC (Change Data Capture) source, ReadBigQueryChangeHistory. This is a significant and well-implemented feature, including the core PTransform, comprehensive unit tests, and integration tests. The architecture is robust, correctly leveraging advanced Beam concepts like Splittable DoFns, stateful DoFns for cleanup, and custom watermark estimators. My review includes suggestions to improve error handling robustness, adhere to Python style guidelines, and clean up some unused code in the integration tests.

@claudevdm claudevdm changed the title Initial BQ CDC [Python] Ad BigQuery Change History source. Feb 27, 2026
@claudevdm claudevdm marked this pull request as ready for review February 27, 2026 19:15
@claudevdm
Copy link
Collaborator Author

R: @damccorm

@github-actions
Copy link
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

@claudevdm claudevdm closed this Feb 27, 2026
@claudevdm claudevdm reopened this Feb 27, 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.

1 participant