Skip to content

Dynamic DDL for DataStream To SQL template#3489

Open
rahulkumar0630 wants to merge 21 commits intomainfrom
v2-dynamic-ddl
Open

Dynamic DDL for DataStream To SQL template#3489
rahulkumar0630 wants to merge 21 commits intomainfrom
v2-dynamic-ddl

Conversation

@rahulkumar0630
Copy link
Contributor

No description provided.

@rahulkumar0630 rahulkumar0630 requested a review from a team as a code owner March 12, 2026 22:11
@rahulkumar0630 rahulkumar0630 added addition New feature or request improvement Making existing code better labels Mar 12, 2026
@google-cla
Copy link

google-cla bot commented Mar 12, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link

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 significantly enhances the DataStream To SQL template by implementing dynamic DDL support. Previously, users had to manually ensure that target database schemas matched the source. With this change, the pipeline can now automatically create new tables and add columns on the fly, streamlining the replication process and reducing operational overhead for schema changes. This feature improves the template's robustness and ease of use for evolving data sources.

Highlights

  • Dynamic DDL Support: Introduced dynamic Data Definition Language (DDL) capabilities, allowing the pipeline to automatically create tables and add columns in the target database as new schema elements appear in the source.
  • Schema Evolution Automation: The template now handles schema evolution by detecting missing tables or columns and executing appropriate DDL statements, removing the need for manual pre-creation of schema objects.
  • New Utility Class for DDL Operations: Added DynamicJdbcDatabase.java to encapsulate the logic for generating and executing DDL statements, including comprehensive type mapping between different database systems (MySQL, Oracle, PostgreSQL).
  • Integration Testing for Dynamic DDL: Included a new integration test (testDataStreamPostgresToPostgresDynamicDDL) to validate the end-to-end functionality of dynamic table creation and column addition in a PostgreSQL target database.
Changelog
  • v2/datastream-to-sql/src/main/java/com/google/cloud/teleport/v2/templates/DataStreamToSQL.java
    • Imported necessary classes for DataStream client and GCP options.
    • Updated Javadoc comments to reflect the new dynamic DDL support.
    • Initialized DataStreamClient and passed it along with databaseType to the CreateDml transform.
  • v2/datastream-to-sql/src/main/java/com/google/cloud/teleport/v2/transforms/CreateDml.java
    • Imported DataStreamClient.
    • Refactored several static configuration fields to instance fields to support dynamic behavior.
    • Added datastreamClient and databaseType as new instance fields.
    • Introduced withDataStreamClient and withDatabaseType methods to configure the transform.
    • Passed the datastreamClient and databaseType to the DatastreamToDML builder.
  • v2/datastream-to-sql/src/main/java/com/google/cloud/teleport/v2/utils/DatastreamToDML.java
    • Imported DataStreamClient.
    • Added datastreamClient, databaseType, and dynamicJdbcDatabase instance fields.
    • Marked dataSource as transient for serialization.
    • Added withDataStreamClient and withDatabaseType methods.
    • Modified setUpTableCache and setUpPrimaryKeyCache to be static and accept DataSource and refreshMinutes.
    • Implemented logic within convertJsonToDmlInfo to check for missing tables or columns and trigger dynamic DDL operations using DynamicJdbcDatabase.
    • Added synchronization around schema cache access to ensure thread safety during DDL operations.
  • v2/datastream-to-sql/src/main/java/com/google/cloud/teleport/v2/utils/DynamicJdbcDatabase.java
    • Added new utility class DynamicJdbcDatabase.
    • Provided methods to createTable and addColumn in a target JDBC database.
    • Implemented logic to fetch source schema from Datastream and generate target-specific DDL.
    • Included comprehensive type mapping functions for MySQL, Oracle, and PostgreSQL.
  • v2/datastream-to-sql/src/test/java/com/google/cloud/teleport/v2/templates/DataStreamToPostgresIT.java
    • Added testDataStreamPostgresToPostgresDynamicDDL integration test to verify dynamic DDL.
    • Implemented helper methods addColumnToSource, checkDestinationColumnExists, and writePostgresDataWithNewColumn for the new test scenario.
    • Introduced a small Thread.sleep in writePostgresData to prevent timestamp collisions.
    • Updated a log message for replication slot cleanup.
Activity
  • This is a new pull request, and no specific activity has been recorded yet.
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.

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 16.31799% with 400 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.15%. Comparing base (5b99af0) to head (845bff1).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
...e/cloud/teleport/v2/utils/DynamicJdbcDatabase.java 0.29% 333 Missing ⚠️
...oogle/cloud/teleport/v2/utils/DatastreamToDML.java 58.77% 39 Missing and 8 partials ⚠️
...e/cloud/teleport/v2/templates/DataStreamToSQL.java 0.00% 9 Missing ⚠️
...google/cloud/teleport/v2/transforms/CreateDml.java 55.55% 8 Missing ⚠️
...oogle/cloud/teleport/v2/transforms/ProcessDml.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3489      +/-   ##
============================================
+ Coverage     51.83%   52.15%   +0.32%     
- Complexity     5486     6090     +604     
============================================
  Files          1029     1041      +12     
  Lines         62342    63388    +1046     
  Branches       6836     6965     +129     
============================================
+ Hits          32313    33059     +746     
- Misses        27802    28093     +291     
- Partials       2227     2236       +9     
Components Coverage Δ
spanner-templates 72.19% <ø> (+0.50%) ⬆️
spanner-import-export 68.92% <ø> (-0.12%) ⬇️
spanner-live-forward-migration 80.49% <ø> (+0.02%) ⬆️
spanner-live-reverse-replication 77.88% <ø> (-0.02%) ⬇️
spanner-bulk-migration 89.18% <ø> (+0.68%) ⬆️
gcs-spanner-dv 85.34% <ø> (-0.59%) ⬇️
Files with missing lines Coverage Δ
...oogle/cloud/teleport/v2/transforms/ProcessDml.java 0.00% <0.00%> (ø)
...google/cloud/teleport/v2/transforms/CreateDml.java 66.66% <55.55%> (-3.93%) ⬇️
...e/cloud/teleport/v2/templates/DataStreamToSQL.java 22.07% <0.00%> (-0.83%) ⬇️
...oogle/cloud/teleport/v2/utils/DatastreamToDML.java 70.88% <58.77%> (+36.01%) ⬆️
...e/cloud/teleport/v2/utils/DynamicJdbcDatabase.java 0.29% <0.29%> (ø)

... and 49 files with indirect coverage changes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addition New feature or request improvement Making existing code better size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant