Skip to content

[SpannerToSourceDb] Add bytesToHex and Spanner value helpers to DMLGeneratorUtils - #4667

Closed
aasthabharill wants to merge 3 commits into
GoogleCloudPlatform:mainfrom
aasthabharill:pg-ps-2a-dml-helpers
Closed

aasthabharill wants to merge 3 commits into
GoogleCloudPlatform:mainfrom
aasthabharill:pg-ps-2a-dml-helpers

Conversation

@aasthabharill

@aasthabharill aasthabharill commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

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

Summary

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

This PR is self-contained and safe to merge on its own: it replaces per-byte String.format hex conversion in DMLGeneratorUtils.convertBase64ToRawHex with a zero-allocation lookup-table bytesToHex helper, and adds shared Spanner JSON value, non-finite float/numeric, and NUL-byte helpers used by parameterized DML generators.

Implementation & Why

  • DMLGeneratorUtils (dbutils/dml/DMLGeneratorUtils.java):
    • Added bytesToHex(byte[]) using a HEX_DIGITS lookup string and switched convertBase64ToRawHex to use it (eliminating per-byte String.format allocations on binary columns).
    • Added isFloatOrNumeric, isNonFiniteLiteral, and getNonFiniteText so JDBC generators detect NaN, Infinity, +Infinity, and -Infinity before calling JSONObject.getBigDecimal (which throws NumberFormatException/JSONException).
    • Added getSpannerStringValue (preserving exact decimal text on string-encoded NUMERIC/PG_NUMERIC instead of reformatting 0.0000001 as 1E-7, avoiding Float->double widening noise on programmatic Floats, and keeping legacy ARRAY<STRING> comma-joining for scalar text columns) and removeNullBytes.
  • Tests (DMLGeneratorUtilsTest.java):
    • Added @RunWith(JUnit4.class) and unit tests testBytesToHex, testNonFiniteHelpers, and testGetSpannerStringValue_PreservesNumericDecimalTextAndFormatsTypes.

Verification

  • Local: mvn -pl v2/spanner-common,v2/spanner-custom-shard,v2/spanner-to-sourcedb test spotless:check (Checkstyle, Spotless, and unit tests passed).

Series Context

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.78082% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.47%. Comparing base (716a5e0) to head (dd6680a).

Files with missing lines Patch % Lines
...rt/v2/templates/dbutils/dml/DMLGeneratorUtils.java 86.53% 1 Missing and 6 partials ⚠️
.../templates/dbutils/dml/PreparedStatementValue.java 92.18% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4667      +/-   ##
============================================
+ Coverage     59.72%   66.47%   +6.75%     
+ Complexity     8218     3343    -4875     
============================================
  Files          1122      552     -570     
  Lines         72762    32717   -40045     
  Branches       8855     3793    -5062     
============================================
- Hits          43454    21750   -21704     
+ Misses        26405     9886   -16519     
+ Partials       2903     1081    -1822     
Components Coverage Δ
spanner-templates 84.11% <91.78%> (+0.08%) ⬆️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 87.57% <ø> (-0.09%) ⬇️
spanner-live-reverse-replication 80.15% <91.78%> (+0.21%) ⬆️
spanner-bulk-migration 88.24% <ø> (-0.05%) ⬇️
gcs-spanner-dv 86.48% <ø> (-0.10%) ⬇️
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 94.73% <86.53%> (-4.31%) ⬇️

... and 594 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 superseded by merged PR #4644, which already added getSpannerValueAsString, getNonFiniteText, isFloatOrPgNumeric, and isStringArray to DMLGeneratorUtils. The remaining PostgreSQL-only helpers are kept private inside PostgreSQLDMLGenerator in #4664 so DMLGeneratorUtils needs no changes.

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