feat(sourcedb-to-spanner): add mapping support for missing postgresql data types - #4075
feat(sourcedb-to-spanner): add mapping support for missing postgresql data types#4075jsuhani-2026 wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is ❌ 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
🚀 New features to boost your workflow:
|
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| private static final ResultSetValueMapper<String> moneyToAvro = | ||
| (value, schema) -> { | ||
| if (value == null) { | ||
| return null; | ||
| } | ||
| return value.replaceAll("[^0-9\\.\\-]", ""); | ||
| }; |
There was a problem hiding this comment.
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();There was a problem hiding this comment.
what was the conclusion on this ?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
…res data types. Expanded integration tests across GoogleSQL and PG Dialect schemas
eaf7d75 to
bc8a1f1
Compare
Added mapping support for several PostgreSQL data types in the
sourcedb-to-spannertemplate and expanded the integration tests to include the missing test coverage for existing mappings.Key Changes:
CIDR,INET)TIME,TIMETZ,INTERVAL)MONEY,UUIDPostgreSQLDataTypesITandPostgreSQLDataTypesPGDialectITto thoroughly test these newly supported data types.