admin管理员组文章数量:1405571
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!
版权声明:本文标题:jdbc - Apache Calcite with PostgreSQL: “DECIMAL precision 0 must be between 1 and 19” Exception - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744262467a2597784.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论