Skip to content

[SpannerToSourceDb] Unify DMLGeneratorUtils column walker and fix null custom NPE - #4668

Closed
aasthabharill wants to merge 4 commits into
GoogleCloudPlatform:mainfrom
aasthabharill:pg-ps-2b-dml-walker
Closed

aasthabharill wants to merge 4 commits into
GoogleCloudPlatform:mainfrom
aasthabharill:pg-ps-2b-dml-walker

Conversation

@aasthabharill

@aasthabharill aasthabharill commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Stacked on #4662, #4666, and #4667: Because GitHub targets main for fork PRs, this PR currently includes earlier commits and will be rebased onto main once #4667 merges. To review only this PR's changes now, inspect commit 7a41de24c (2 files: DMLGeneratorUtils.java, DMLGeneratorUtilsTest.java; +266 / -114).

Summary

Part 4 of 7 for migrating v2/spanner-to-sourcedb JDBC reverse-replication writers to PreparedStatement execution (follows #4667; split out of combined prototype #4655).

This PR is self-contained and safe to merge on its own: it refactors DMLGeneratorUtils.getColumnValues and getPkColumnValues onto a shared private generic column walker (resolveNonPkColumns / resolvePkColumns) in preparation for getColumnBindings, and fixes a NullPointerException when custom transformations return null across MySQL, Oracle, and SQL Server.

Behavioral change (MySQL, Oracle, SQL Server): When a custom transformation returns null for a column, getColumnValues / getPkColumnValues now resolves that column to SQL NULL instead of throwing NullPointerException and sending the record to the permanent-error queue.

Implementation & Why

  • DMLGeneratorUtils (dbutils/dml/DMLGeneratorUtils.java):
    • Extracted shared private helpers resolveNonPkColumns, resolvePkColumns, resolveSpannerColumn, and selectValuesJson parameterized on value type <V>.
    • Why: isolating this refactor in its own PR lets reviewers verify line-by-line behavioral equivalence for legacy MySQL, Oracle, SQL Server, and PostgreSQL callers before ColumnBinding APIs are layered on top in [SpannerToSourceDb] Add ColumnBinding and DMLGeneratorUtils binding APIs #4663.
    • Null-guarded customTransformationResponse.get(colName), newValuesJson, keyValuesJson, and sourceTable.primaryKeyColumns().
    • Added a TODO to evaluate returning null when a non-generated composite PK column has no Spanner mapping (pre-existing behavior preserved for compatibility with existing tests).
  • Tests (DMLGeneratorUtilsTest.java):
    • Added testLegacyGetColumnAndPkValues_HandleNullCustomTransformationWithoutNpe verifying both non-PK and PK paths handle null custom transformation outputs cleanly.

Verification

  • Local: mvn -pl v2/spanner-common,v2/spanner-custom-shard,v2/spanner-to-sourcedb test spotless:check (Checkstyle, Spotless, and unit tests passed).
  • CI: Existing MySQL, Oracle, SQL Server, and PostgreSQL reverse-replication ITs verify the unified column walker with zero regressions.

Series Context

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.78744% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.46%. Comparing base (716a5e0) to head (7a41de2).

Files with missing lines Patch % Lines
...rt/v2/templates/dbutils/dml/DMLGeneratorUtils.java 89.38% 2 Missing and 10 partials ⚠️
.../templates/dbutils/dml/PreparedStatementValue.java 92.18% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4668      +/-   ##
============================================
+ Coverage     59.72%   66.46%   +6.74%     
+ Complexity     8218     3352    -4866     
============================================
  Files          1122      552     -570     
  Lines         72762    32713   -40049     
  Branches       8855     3791    -5064     
============================================
- Hits          43454    21742   -21712     
+ Misses        26405     9887   -16518     
+ Partials       2903     1084    -1819     
Components Coverage Δ
spanner-templates 84.09% <91.78%> (+0.05%) ⬆️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 87.59% <ø> (-0.08%) ⬇️
spanner-live-reverse-replication 80.10% <91.78%> (+0.16%) ⬆️
spanner-bulk-migration 88.25% <ø> (-0.04%) ⬇️
gcs-spanner-dv 86.49% <ø> (-0.09%) ⬇️
Files with missing lines Coverage Δ
...eport/v2/templates/dbutils/dao/source/JdbcDao.java 100.00% <100.00%> (+40.54%) ⬆️
.../templates/dbutils/dml/PreparedStatementValue.java 92.18% <92.18%> (ø)
...rt/v2/templates/dbutils/dml/DMLGeneratorUtils.java 91.21% <89.38%> (-7.83%) ⬇️

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

@aasthabharill

Copy link
Copy Markdown
Member Author

Closing as fully superseded by merged PR #4644, which already unified the DMLGeneratorUtils column walker and fixed the null custom transformation NPE. Active PostgreSQL changes continue in #4664.

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