Skip to content

[SourceDbToSpanner] Use prepared statements for Spanner to MySQL - #4644

Merged
darshan-sj merged 6 commits into
GoogleCloudPlatform:mainfrom
darshan-sj:reverse-vuln
Dec 2, 2026
Merged

darshan-sj merged 6 commits into
GoogleCloudPlatform:mainfrom
darshan-sj:reverse-vuln

Conversation

@darshan-sj

Copy link
Copy Markdown
Contributor

No description provided.

@darshan-sj
darshan-sj requested a review from a team as a code owner November 27, 2026 07:24
@darshan-sj darshan-sj added the improvement Making existing code better label Nov 27, 2026
@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 refactors the Spanner-to-MySQL migration logic to utilize JDBC prepared statements instead of manual string concatenation for DML generation. This change mitigates SQL injection risks by separating SQL structure from record data. The update includes new model classes to manage typed parameters and updates to the DML generation utilities to ensure all column values, including custom transformations and timezone offsets, are correctly bound as parameters.

Highlights

  • Prepared Statements Implementation: Transitioned from string-concatenated DML statements to JDBC PreparedStatement for Spanner-to-MySQL migration, significantly improving security against SQL injection.
  • New Data Models: Introduced 'ColumnBinding' and 'PreparedStatementValue' classes to encapsulate SQL fragments and their corresponding typed parameters, ensuring consistent data binding.
  • Refactored DML Generation: Updated 'MySQLDMLGenerator' and 'DMLGeneratorUtils' to support parameterized queries, including handling of custom transformations and timezone conversions as bound parameters.
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 MySQL DML generation logic to use parameterized queries via PreparedStatement instead of string interpolation, significantly improving security against SQL injection. It introduces PreparedStatementValue and ColumnBinding models to manage typed parameters and updates JdbcDao and DMLGeneratorUtils to support parameter binding. The review feedback highlights two potential issues in MySQLDMLGenerator: a possible NumberFormatException when parsing special float values like NaN or Infinity as BigDecimal, and a potential StringIndexOutOfBoundsException or truncation issue when unconditionally trimming the trailing 'Z' from timestamp strings.

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.34641% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.55%. Comparing base (32a17dc) to head (d7ad66b).

Files with missing lines Patch % Lines
...t/v2/templates/source/mysql/MySQLDMLGenerator.java 98.34% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4644      +/-   ##
============================================
+ Coverage     60.13%   66.55%   +6.41%     
+ Complexity     8845     4253    -4592     
============================================
  Files          1123      572     -551     
  Lines         72848    35075   -37773     
  Branches       8855     4037    -4818     
============================================
- Hits          43808    23343   -20465     
+ Misses        26105    10568   -15537     
+ Partials       2935     1164    -1771     
Components Coverage Δ
spanner-templates 86.10% <99.34%> (+0.59%) ⬆️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 87.65% <ø> (ø)
spanner-live-reverse-replication 84.19% <99.34%> (+1.22%) ⬆️
spanner-bulk-migration 88.28% <ø> (ø)
gcs-spanner-dv 86.56% <ø> (ø)
Files with missing lines Coverage Δ
.../java/com/custom/CustomTransformationForDLQIT.java 69.69% <100.00%> (-1.32%) ⬇️
...custom/CustomTransformationWithShardForLiveIT.java 60.86% <100.00%> (+60.86%) ⬆️
...eport/v2/templates/dbutils/dao/source/JdbcDao.java 100.00% <100.00%> (ø)
...leport/v2/templates/dbutils/dml/ColumnBinding.java 100.00% <100.00%> (ø)
...rt/v2/templates/dbutils/dml/DMLGeneratorUtils.java 99.29% <100.00%> (+0.25%) ⬆️
.../templates/dbutils/dml/PreparedStatementValue.java 100.00% <100.00%> (ø)
...t/v2/templates/source/mysql/MySQLDMLGenerator.java 98.84% <98.34%> (+2.26%) ⬆️

... and 570 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.

@darshan-sj

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 transitions the MySQL DML generation from inline SQL literals to parameterized prepared statements, introducing PreparedStatementValue and ColumnBinding to safely bind column values and custom transformation results. The review feedback highlights critical safety improvements: handling potential NullPointerExceptions in DMLGeneratorUtils when custom transformations return null values, and safely checking for a trailing 'Z' before trimming timestamps in MySQLDMLGenerator to prevent StringIndexOutOfBoundsException or data corruption.

@darshan-sj darshan-sj changed the title [DO NOT MERGE] [SourceDbToSpanner] Use prepared statements for Spanner to MySQL [SourceDbToSpanner] Use prepared statements for Spanner to MySQL Nov 29, 2026
@darshan-sj

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 MySQL DML generation process to use parameterized queries instead of SQL literals, enhancing security against SQL injection. It introduces a new ColumnBinding and PreparedStatementValue structure to handle typed parameters, updates MySQLDMLGenerator to build parameterized SQL, and adds a MySQLJdbcDao to manage the binding of these parameters. Additionally, it includes comprehensive updates to existing tests to reflect the new parameterized approach and adds new unit tests for the binding logic.

@bharadwaj-aditya bharadwaj-aditya 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.

Most comments are about standardizing across jdbc flows

@bharadwaj-aditya bharadwaj-aditya 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.

LGTM

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

Labels

improvement Making existing code better size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants