Skip to content

feat(sourcedb-to-spanner): add mapping support for missing postgresql data types - #4075

Open
jsuhani-2026 wants to merge 3 commits into
mainfrom
jsuhani-pg-data-types-parity
Open

feat(sourcedb-to-spanner): add mapping support for missing postgresql data types#4075
jsuhani-2026 wants to merge 3 commits into
mainfrom
jsuhani-pg-data-types-parity

Conversation

@jsuhani-2026

@jsuhani-2026 jsuhani-2026 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Added mapping support for several PostgreSQL data types in the sourcedb-to-spanner template and expanded the integration tests to include the missing test coverage for existing mappings.

Key Changes:

  • New Data Type Support: Added extraction and mapping logic for previously unsupported types, including:
    • Network Types (CIDR, INET)
    • Time & Intervals (TIME, TIMETZ, INTERVAL)
    • MONEY, UUID
  • Updated Avro mappers and logical type converters to seamlessly serialize these new values between the source and Spanner.
  • Expanded PostgreSQLDataTypesIT and PostgreSQLDataTypesPGDialectIT to thoroughly test these newly supported data types.
  • Also added IT coverage for several already-supported data type mappings that were previously missing from the integration tests.

@jsuhani-2026 jsuhani-2026 added the addition New feature or request label Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.45098% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.84%. Comparing base (64ce303) to head (bc8a1f1).

Files with missing lines Patch % Lines
...owmapper/provider/PostgreSQLJdbcValueMappings.java 66.66% 12 Missing and 7 partials ⚠️
...er/migrations/avro/GenericRecordTypeConvertor.java 90.32% 1 Missing and 2 partials ⚠️
.../v2/spanner/migrations/avro/AvroToValueMapper.java 83.33% 0 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (77.45%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@              Coverage Diff              @@
##               main    #4075       +/-   ##
=============================================
+ Coverage     35.88%   63.84%   +27.95%     
- Complexity      716     2690     +1974     
=============================================
  Files           251      557      +306     
  Lines         17157    31626    +14469     
  Branches       1741     3499     +1758     
=============================================
+ Hits           6157    20192    +14035     
+ Misses        10488    10391       -97     
- Partials        512     1043      +531     
Components Coverage Δ
spanner-templates 87.34% <77.45%> (∅)
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 89.23% <89.18%> (∅)
spanner-live-reverse-replication 83.18% <89.18%> (∅)
spanner-bulk-migration 92.08% <77.45%> (∅)
gcs-spanner-dv 88.50% <89.18%> (∅)
Files with missing lines Coverage Δ
...ource/postgres/PostgresSrcToSpSourceConnector.java 99.00% <100.00%> (ø)
.../v2/spanner/migrations/avro/AvroToValueMapper.java 93.27% <83.33%> (ø)
...er/migrations/avro/GenericRecordTypeConvertor.java 95.67% <90.32%> (ø)
...owmapper/provider/PostgreSQLJdbcValueMappings.java 89.07% <66.66%> (ø)

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

@jsuhani-2026
jsuhani-2026 marked this pull request as ready for review July 29, 2026 12:17
@jsuhani-2026
jsuhani-2026 requested a review from a team as a code owner July 29, 2026 12:17
@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 enhances the sourcedb-to-spanner migration template by adding support for a wide range of PostgreSQL data types that were previously unsupported. The changes include updates to the source connector, row mappers, and Avro conversion logic to facilitate seamless data migration. Additionally, the test suite has been updated to verify these new mappings and ensure robust performance across different data scenarios.

Highlights

  • Expanded Data Type Support: Added comprehensive mapping support for PostgreSQL data types including Network types (CIDR, INET), Bit Strings (BIT, VARBIT), Time/Interval types, MONEY, and UUID.
  • Converter and Mapper Enhancements: Updated Avro mappers and logical type converters to ensure accurate serialization and parity between the source database and Cloud Spanner.
  • Integration Test Coverage: Significantly expanded PostgreSQLDataTypesIT and PostgreSQLDataTypesPGDialectIT to include the new types and address previously missing test coverage for existing mappings.
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 adds support for several PostgreSQL data types (including CIDR, INET, INTERVAL, MONEY, and various TIME/TIMETZ formats) in the PostgreSQL to Spanner source connector, updating mapping providers, JDBC value mappings, Avro value mappers, and integration tests. The review feedback highlights several critical issues: parsing MONEY values via regex is fragile and locale-dependent, and should instead use ResultSet::getBigDecimal; converting TIME values to ISO-8601 duration strings is inconsistent and should be replaced with standard ISO local time formatting; calling value.array() directly on a ByteBuffer is risky and should be replaced with a safer byte-copying approach; and reassigning lambda parameters should be avoided to improve code maintainability.

Comment on lines +131 to +137
private static final ResultSetValueMapper<String> moneyToAvro =
(value, schema) -> {
if (value == null) {
return null;
}
return value.replaceAll("[^0-9\\.\\-]", "");
};

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.

high

Using ResultSet::getString and regex replacement (replaceAll("[^0-9\\.\\-]", "")) to parse MONEY values is highly fragile and prone to silent data corruption. Depending on the database's lc_monetary locale setting, negative monetary values can be formatted with parentheses (e.g., ($1,234.56)), which would have the parentheses stripped and incorrectly become positive (1234.56). Additionally, locales using commas as decimal separators (e.g., 1.234,56 €) will have the comma stripped, leading to incorrect values (e.g., 1.23456 instead of 1234.56). To avoid these locale-specific formatting issues, retrieve the value directly as a java.math.BigDecimal using ResultSet::getBigDecimal.

  private static final ResultSetValueMapper<java.math.BigDecimal> moneyToAvro =
      (value, schema) -> value == null ? null : value.toPlainString();

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.

what was the conclusion on this ?

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.

Not yet concluded, will have a sync with datastream team on Monday

return (int) Math.min((length * 4) + 24, Integer.MAX_VALUE);
})
.put("MONEY", ResultSet::getDouble, valuePassThrough, 8)
.put("MONEY", ResultSet::getString, moneyToAvro, 8)

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.

high

Use ResultSet::getBigDecimal instead of ResultSet::getString to retrieve the MONEY value robustly without locale-specific formatting issues.

Suggested change
.put("MONEY", ResultSet::getString, moneyToAvro, 8)
.put("MONEY", ResultSet::getBigDecimal, moneyToAvro, 8)

…res data types. Expanded integration tests across GoogleSQL and PG Dialect schemas
@jsuhani-2026
jsuhani-2026 force-pushed the jsuhani-pg-data-types-parity branch from eaf7d75 to bc8a1f1 Compare July 31, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addition New feature or request size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants