Skip to content

[SpannerToSourceDb] Expand SpannerToPostgreSQLDataTypesIT CRUD and PK coverage - #4665

Draft
aasthabharill wants to merge 7 commits into
GoogleCloudPlatform:mainfrom
aasthabharill:pg-ps-4-postgres-it
Draft

aasthabharill wants to merge 7 commits into
GoogleCloudPlatform:mainfrom
aasthabharill:pg-ps-4-postgres-it

Conversation

@aasthabharill

@aasthabharill aasthabharill commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Stacked on #4664: Review commit f0ca6e72d (3 files). Will be rebased onto main once #4664 merges.

Why This Change Is Required

SpannerToPostgreSQLDataTypesIT previously only tested INSERT into bigint-PK tables for a small set of scalar types. Because #4664 changes how PostgreSQLDMLGenerator binds parameter OIDs across INSERT, UPDATE, and DELETE, we need real Spanner-to-PostgreSQL integration coverage to verify real PK deletes, non-finite floats, USER-DEFINED enums, time without time zone, character(n) padding, and IS NULL generated-PK deletes end to end.

Changes Made & What They Do

  • postgresql-schema.sql & spanner-schema.sql:
    • Adds tables for real (NaN, Infinity, -Infinity, 1.1), bytes_to_text, time without time zone, timestamp without time zone, and mood_enum (USER-DEFINED ENUM).
    • Adds 11 non-bigint primary-key tables (real, double precision, numeric, uuid, date, timestamptz, bytea, boolean, integer, text with quotes, character(10)).
    • Adds gen_pk_table with a GENERATED ALWAYS AS (...) STORED PRIMARY KEY.
  • SpannerToPostgreSQLDataTypesIT.java:
    • Phase 1 (INSERT): Inserts across all datatype tables, all 11 non-bigint PK tables (including exact-length, shorter, and trailing-space keys on character(10)), and gen_pk_table; verifies exact row counts and column/PK values.
    • Phase 2 (UPDATE): Updates all 11 PK tables and updates gen_pk_table.last_name to NULL via ON CONFLICT DO UPDATE SET.
    • Phase 3 (DELETE): Deletes all 11 PK tables and gen_pk_table (verifying symmetrical PK binding and "last_name" IS NULL matching); asserts 0 remaining rows.
    • Tightens assertRowInPostgreSQL with exact row-count (hasSize) checks.

Verification

  • Local Maven (JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64, -Dbeam.version=2.77.0):
    • mvn -pl v2/spanner-common,v2/spanner-custom-shard,v2/spanner-to-sourcedb test: SpannerToPostgreSQLDataTypesIT compiles cleanly, 1,243 unit tests passed, 0 Checkstyle violations.
    • mvn -pl v2/spanner-to-sourcedb spotless:check: passed.
  • GitHub Actions CI: Build, Checkstyle, Spotless, Unit Tests, Dataflow Templates Integration Smoke Tests, and Dataflow Templates Integration Tests (including the expanded SpannerToPostgreSQLDataTypesIT against real Cloud Spanner, Dataflow, and PostgreSQL) all passed.

Related / Follow-up PRs

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.45983% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.93%. Comparing base (e4ea790) to head (f0ca6e7).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...plates/source/postgres/PostgreSQLDMLGenerator.java 94.20% 5 Missing and 15 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4665      +/-   ##
============================================
+ Coverage     60.34%   67.93%   +7.59%     
+ Complexity     8965     3649    -5316     
============================================
  Files          1125      555     -570     
  Lines         72994    33079   -39915     
  Branches       8888     3842    -5046     
============================================
- Hits          44049    22473   -21576     
+ Misses        26016     9496   -16520     
+ Partials       2929     1110    -1819     
Components Coverage Δ
spanner-templates 86.24% <94.45%> (+0.13%) ⬆️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 87.63% <ø> (-0.03%) ⬇️
spanner-live-reverse-replication 84.50% <94.45%> (+0.30%) ⬆️
spanner-bulk-migration 88.29% <ø> (+<0.01%) ⬆️
gcs-spanner-dv 86.54% <ø> (-0.04%) ⬇️
Files with missing lines Coverage Δ
...rt/v2/templates/dbutils/dml/DMLGeneratorUtils.java 99.31% <100.00%> (+0.01%) ⬆️
.../templates/dbutils/dml/PreparedStatementValue.java 100.00% <100.00%> (ø)
...t/v2/templates/source/mysql/MySQLDMLGenerator.java 98.84% <100.00%> (ø)
...v2/templates/source/oracle/OracleDMLGenerator.java 79.41% <100.00%> (ø)
...plates/source/sqlserver/SQLServerDMLGenerator.java 93.65% <100.00%> (-0.04%) ⬇️
...plates/source/postgres/PostgreSQLDMLGenerator.java 94.89% <94.20%> (+3.56%) ⬆️

... and 601 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
aasthabharill marked this pull request as ready for review December 2, 2026 20:26
@aasthabharill
aasthabharill requested a review from a team as a code owner December 2, 2026 20:26
@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 introduces significant improvements to the PostgreSQL reverse replication process by moving to a fully parameterized PreparedStatement approach. This change ensures that data types are correctly handled by the PostgreSQL driver, preventing issues with unquoted identifiers or incorrect type resolution. The PR also significantly expands the integration test suite to validate these changes against real Cloud Spanner and PostgreSQL instances, ensuring robust support for various data types and primary key configurations.

Highlights

  • PostgreSQL DML Generation Refactoring: Refactored PostgreSQLDMLGenerator to use parameterized PreparedStatements for all column values, improving type safety and handling of complex data types like JSON, UUID, and Enums.
  • Integration Test Expansion: Expanded SpannerToPostgreSQLDataTypesIT to include comprehensive CRUD and primary key coverage, verifying INSERT, UPDATE (with ON CONFLICT), and DELETE operations across various data types.
  • Breaking Change Documentation: Added documentation in README regarding the breaking change where reverse replication now strictly requires raw data binding rather than SQL fragments.
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 updates the Spanner-to-PostgreSQL reverse replication template to use strictly parameterized DML statements with PreparedStatement bindings instead of raw SQL fragments. It introduces PreparedStatementValue.ofUntypedString using Types.OTHER to allow PostgreSQL to natively parse string parameters into target column types like jsonb, uuid, and enums. The PostgreSQLDMLGenerator has been refactored to handle type-specific bindings, strip NUL characters, format bytes as hex, and support non-finite floating-point values. Additionally, integration tests and schemas have been expanded to cover INSERT, UPDATE, and DELETE operations across a wide range of PostgreSQL data types and primary key configurations. I have no further feedback to provide.

@aasthabharill
aasthabharill marked this pull request as draft December 3, 2026 05:46
aasthabharill and others added 4 commits December 4, 2026 07:10
…ases

- Restore the list + String.join form of getUpsertStatement and the
  INTEGER_LITERAL regex, replacing the hand-written fast paths.
- PgColumnType.fromSourceType does a single normalized lookup.
- Inline getBooleanBindingValue and formatConversionError; make
  isSpannerFloat a local variable.
- isNonFiniteTrimmed uses a Locale.ROOT lower-cased set lookup again, so
  only ASCII spellings of NaN / Infinity match (equalsIgnoreCase also
  matched the Turkish dotless and dotted i).
- Reword comments on NULL timestamp placeholders and dropped exception
  causes to say what the code guarantees.
- Tests: string "false" into boolean columns, non-finite text via Spanner
  STRING and custom values, INT64 string edge cases (0, -0, out of long
  range, non-numeric, BigInteger), and decimals in the shape org.json
  parses from text.
… sources

- getNullColumnBinding returns a NULL with the JDBC type of the column's
  non-null values (VARCHAR, BIGINT, BOOLEAN, DOUBLE, DECIMAL, VARBINARY).
  pgjdbc reuses a server-prepared statement only while parameter types stay
  the same, so an untyped NULL forced a Close and re-Parse whenever a column
  switched between NULL and a value. Timestamp and untyped (Types.OTHER)
  columns keep an untyped NULL, which already matches their values.
- Null custom transformation values use the same mapping.
- Oracle and SQL Server call DMLGeneratorUtils.removeNullBytes instead of
  their own inline copy of the same replace.
- Tests: one test pinning that a NULL binds with the placeholder and
  parameter type of the column's values, and updated NULL expectations.
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