Skip to content

[#10519] fix(postgresql): handle unconstrained NUMERIC type with precision=0#10534

Open
yuqi1129 wants to merge 1 commit intoapache:mainfrom
yuqi1129:fix-10519-postgresql-unconstrained-numeric
Open

[#10519] fix(postgresql): handle unconstrained NUMERIC type with precision=0#10534
yuqi1129 wants to merge 1 commit intoapache:mainfrom
yuqi1129:fix-10519-postgresql-unconstrained-numeric

Conversation

@yuqi1129
Copy link
Contributor

What changes were proposed in this pull request?

In PostgreSqlTypeConverter.toGravitino(), when a PostgreSQL column is defined as NUMERIC without explicit precision/scale, the JDBC driver returns columnSize=0. This was passed directly to Types.DecimalType.of(0, ...) which rejects precision=0 with an IllegalArgumentException.

Fix: map columnSize=null or columnSize=0 to DECIMAL(38, 18) — the maximum supported precision with a sensible default scale.

Why are the changes needed?

Fix: #10519

Unconstrained NUMERIC columns 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 NUMERIC columns now succeeds, returning DECIMAL(38, 18) instead of throwing an error.

How was this patch tested?

Added unit tests in TestPostgreSqlTypeConverter for both columnSize=0 and columnSize=null cases.

Copilot AI review requested due to automatic review settings March 24, 2026 11:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 unconstrained NUMERIC (columnSize == null || columnSize == 0) to DECIMAL(38, 18) instead of attempting to construct an invalid decimal type.
  • Add unit tests to cover both columnSize=0 and columnSize=null cases for NUMERIC.

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>
@yuqi1129 yuqi1129 force-pushed the fix-10519-postgresql-unconstrained-numeric branch from 865006a to f900e42 Compare March 24, 2026 11:36
@github-actions
Copy link

Code Coverage Report

Overall Project 64.86% +0.07% 🟢
Files changed 86.11% 🟢

Module Coverage
aliyun 1.73% 🔴
api 47.14% 🟢
authorization-common 85.96% 🟢
aws 1.1% 🔴
azure 2.6% 🔴
catalog-common 10.0% 🔴
catalog-fileset 80.02% 🟢
catalog-hive 80.98% 🟢
catalog-jdbc-clickhouse 79.06% 🟢
catalog-jdbc-common 42.89% 🟢
catalog-jdbc-doris 80.28% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.23% 🟢
catalog-jdbc-oceanbase 78.38% 🟢
catalog-jdbc-postgresql 82.35% +2.91% 🟢
catalog-jdbc-starrocks 78.27% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 45.07% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 87.15% 🟢
catalog-lakehouse-paimon 77.71% 🟢
catalog-model 77.72% 🟢
cli 44.51% 🟢
client-java 77.83% 🟢
common 49.42% 🟢
core 80.96% 🟢
filesystem-hadoop3 76.97% 🟢
flink 38.86% 🔴
flink-runtime 0.0% 🔴
gcp 14.2% 🔴
hadoop-common 10.39% 🔴
hive-metastore-common 45.82% 🟢
iceberg-common 50.21% 🟢
iceberg-rest-server 66.24% +0.8% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 23.88% 🔴
lance-rest-server 57.84% 🟢
lineage 53.02% 🟢
optimizer 82.95% 🟢
optimizer-api 21.95% 🔴
server 85.6% 🟢
server-common 69.43% 🟢
spark 32.79% 🔴
spark-common 39.09% 🔴
trino-connector 31.62% 🔴
Files
Module File Coverage
catalog-jdbc-postgresql PostgreSqlTypeConverter.java 98.88% 🟢
iceberg-rest-server IcebergTableOperations.java 79.14% 🟢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][PostgreSQL] Table load fails for columns with unconstrained NUMERIC type (precision=0)

2 participants