mihaibudiu commented on code in PR #4872:
URL: https://github.com/apache/calcite/pull/4872#discussion_r3067272227
##########
core/build.gradle.kts:
##########
@@ -95,6 +95,9 @@ dependencies {
testImplementation("org.apache.commons:commons-pool2")
testImplementation("org.hsqldb:hsqldb::jdk8")
testImplementation("sqlline:sqlline")
+ testImplementation("com.oracle.ojdbc:ojdbc8")
+ testImplementation("org.postgresql:postgresql:42.7.3")
Review Comment:
this suggestion seems important
##########
core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java:
##########
@@ -448,9 +448,27 @@ private static RelDataType sqlType(RelDataTypeFactory
typeFactory, int dataType,
if (precision >= 0
&& scale >= 0
&& sqlTypeName.allowsPrecScale(true, true)) {
+
+ // Fix for CALCITE-6654:
+ // Oracle, Postgres and MSSQL report precision=0 for DECIMAL/NUMERIC
+ // columns without explicit precision. Calcite rejects precision=0
+ // since 1.38.0. Treat as unspecified precision.
+ if (precision == 0 && isAffectedTypeForMissingPrecision(sqlTypeName)) {
+ return typeFactory.createSqlType(sqlTypeName);
+ }
+
return typeFactory.createSqlType(sqlTypeName, precision, scale);
+
} else if (precision >= 0 && sqlTypeName.allowsPrecNoScale()) {
+
+ // Fix for CALCITE-6654:
+ // Oracle returns scale=-127 for NUMBER without precision
Review Comment:
The comment about oracle is informative, but it's not clear how it relates
to the code here.
##########
core/src/test/java/org/apache/calcite/jdbc/JdbcSchemaDecimalBugTest.java:
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.jdbc;
+
+import org.apache.calcite.adapter.jdbc.JdbcSchema;
+import org.apache.calcite.schema.SchemaPlus;
+
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.Statement;
+import java.util.Properties;
+import java.util.logging.Logger;
+import javax.sql.DataSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+/**
+ * Integration tests for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-6654">[CALCITE-6654]
+ * JdbcSchema throws error for NUMERIC/DECIMAL columns without explicit
+ * precision (Oracle, PostgreSQL, MSSQL)</a>.
+ *
+ * <p>These are <b>integration tests</b> that require live database instances.
+ * Run with: {@code ./gradlew :core:test -Dcalcite.integration.tests=true}
+ *
+ * <p>Required Docker containers:
+ * <ul>
+ * <li>Oracle Free - localhost:1521/FREEPDB1 (user: system /
testpass)</li>
+ * <li>PostgreSQL - localhost:5432/testdb (user: testuser /
testpass)</li>
+ * <li>SQL Server - localhost:1433/master (user: sa /
TestPass123!)</li>
+ * </ul>
+ *
+ * <p>If a database is unreachable the test is skipped, not failed.
+ */
+@Tag("integration")
+@EnabledIfSystemProperty(named = "calcite.integration.tests", matches = "true")
+public class JdbcSchemaDecimalBugTest {
Review Comment:
I don't understand where the DECIMAL without precision is.
Where is this table test_numbers?
##########
core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java:
##########
@@ -568,6 +586,13 @@ private Factory() {}
}
}
+ private static boolean isAffectedTypeForMissingPrecision(SqlTypeName
sqlTypeName) {
Review Comment:
This function looks like overkill.
Do you expect it will need to cover other cases too?
I would just inline the function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]