[#10519] fix(postgresql): handle unconstrained NUMERIC type with precision=0#10534
Open
yuqi1129 wants to merge 1 commit intoapache:mainfrom
Open
[#10519] fix(postgresql): handle unconstrained NUMERIC type with precision=0#10534yuqi1129 wants to merge 1 commit intoapache:mainfrom
yuqi1129 wants to merge 1 commit intoapache:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes PostgreSQL NUMERIC type conversion when the column is declared without explicit precision/scale (unconstrained NUMERIC), which can show up from JDBC metadata as columnSize=0 (or null) and previously caused an IllegalArgumentException in Types.DecimalType.of(...).
Changes:
- Update
PostgreSqlTypeConverter.toGravitino()to map unconstrainedNUMERIC(columnSize == null || columnSize == 0) toDECIMAL(38, 18)instead of attempting to construct an invalid decimal type. - Add unit tests to cover both
columnSize=0andcolumnSize=nullcases forNUMERIC.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlTypeConverter.java |
Adds guard logic for unconstrained NUMERIC and defaults it to DECIMAL(38, 18) to prevent precision=0 failures. |
catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/converter/TestPostgreSqlTypeConverter.java |
Adds regression coverage for NUMERIC with columnSize=0 and columnSize=null. |
…h precision=0 Map unconstrained NUMERIC (no precision/scale) columns to DECIMAL(38, 18) instead of throwing IllegalArgumentException. PostgreSQL JDBC metadata returns columnSize=0 for NUMERIC columns without explicit precision, which was passed directly to Types.DecimalType.of() causing a validation failure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
865006a to
f900e42
Compare
Code Coverage Report
Files
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
In
PostgreSqlTypeConverter.toGravitino(), when a PostgreSQL column is defined asNUMERICwithout explicit precision/scale, the JDBC driver returnscolumnSize=0. This was passed directly toTypes.DecimalType.of(0, ...)which rejects precision=0 with anIllegalArgumentException.Fix: map
columnSize=nullorcolumnSize=0toDECIMAL(38, 18)— the maximum supported precision with a sensible default scale.Why are the changes needed?
Fix: #10519
Unconstrained
NUMERICcolumns are valid in PostgreSQL and commonly used. Loading any table containing such a column was completely broken.Does this PR introduce any user-facing change?
Yes — loading tables with unconstrained
NUMERICcolumns now succeeds, returningDECIMAL(38, 18)instead of throwing an error.How was this patch tested?
Added unit tests in
TestPostgreSqlTypeConverterfor bothcolumnSize=0andcolumnSize=nullcases.