jdbc - Apache Calcite with PostgreSQL: “DECIMAL precision 0 must be between 1 and 19” Exception - Stack Overflow

I am using Apache Calcite 1.38.0 along with the PostgreSQL JDBC driver version 42.7.2. When executing a

I am using Apache Calcite 1.38.0 along with the PostgreSQL JDBC driver version 42.7.2. When executing an SQL query through a JdbcSchema connection to my PostgreSQL database, I encountered an exception.

Code to initialize the connection:

BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl(MY_PG_URL);
dataSource.setUsername(MY_PG_USERNAME);
dataSource.setPassword(MY_PG_PWD);

JdbcSchema.create(
    rootSchema, 
    "pgSchema", 
    dataSource, 
    null, 
    "public"
); 
// rootSchema is obtained from CalciteConnection.getRootSchema()

PostgreSQL table DDL:

CREATE TABLE test_table (
    value NUMERIC -- A NUMERIC column without specifying precision and scale
);

Query execution:

String sql = "SELECT * FROM pgSchema.test_table";
Statement statement = calciteConnection.createStatement();
statement.executeQuery(sql);

Exception encountered:

** .apache.calcite.runtime.CalciteException: DECIMAL precision 0 must be between 1 and 19**

Investigation:

From my analysis, when PgDatabaseMetaData#getColumns retrieves column metadata, if the NUMERIC column does not explicitly specify precision and scale (i.e., its atttypmod is -1), TypeInfoCache#getPrecision and getScale return 0. This causes SqlTypeFactoryImpl#createSqlType in Calcite to fail validation for precision, leading to this exception.

Questions: 1. Is this a bug in Apache Calcite? 2. Is there any workaround to resolve this issue?

Any insights would be greatly appreciated!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744262467a4565702.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信