Alexis Cubilla created CALCITE-7524:
---------------------------------------

             Summary: JdbcSchema throws exception for DECIMAL columns with 
precision 0 in JDBC metadata
                 Key: CALCITE-7524
                 URL: https://issues.apache.org/jira/browse/CALCITE-7524
             Project: Calcite
          Issue Type: Bug
          Components: jdbc-adapter, jdbc-driver
    Affects Versions: 1.41.0
         Environment: Apache Calcite 1.41.0 or later (SqlTypeFactoryImpl 
rejects DECIMAL precision 0).

PostgreSQL with columns defined as NUMERIC or DECIMAL without explicit 
precision in DDL.

PostgreSQL JDBC driver (for example 42.x).

Reproduction path: JdbcSchema reads column metadata where COLUMN_SIZE is 0 for 
DECIMAL/NUMERIC.
            Reporter: Alexis Cubilla
             Fix For: 1.42.0


Problem
-------

When using JdbcSchema with PostgreSQL (and other JDBC drivers), NUMERIC or 
DECIMAL columns declared without explicit precision in DDL often report 
COLUMN_SIZE = 0 in DatabaseMetaData.

JdbcSchema.sqlType() passes that value to createSqlType(DECIMAL, 0, scale). 
SqlTypeFactoryImpl then rejects precision 0 with an error such as:

DECIMAL precision 0 must be between 1 and 19

The failure occurs while building JDBC column types (schema / row type), for 
example when resolving a table that has such columns. It is not necessarily 
caused by invalid end-user SQL.

Root cause
----------

Some JDBC drivers use column size 0 to mean that numeric precision is not 
specified for unconstrained NUMERIC/DECIMAL. Calcite currently treats 0 as a 
literal DECIMAL precision, which is invalid for the type factory.

Proposed fix
------------

In JdbcSchema.sqlType(), when the SQL type is DECIMAL and the reported 
precision is 0, replace it with 
typeFactory.getTypeSystem().getDefaultPrecision(DECIMAL) before calling 
createSqlType.

Tests
-----

Add JdbcSchemaSqlTypeTest (or equivalent) covering Types.NUMERIC and 
Types.DECIMAL with precision 0 and a positive scale, exercising the sqlType 
mapping path.

Related issues
--------------

This is not the same as CALCITE-5212. CALCITE-5212 concerns 
PRECISION_NOT_SPECIFIED (-1) and DECIMAL digest / DATATYPE_CACHE behavior. This 
issue is only about literal precision 0 coming from JDBC metadata.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to