This is an automated email from the ASF dual-hosted git repository.

mbudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new 3df11895b2 [CALCITE-7043] Type inferred for SqlItemOperator has 
incorrect nullability
3df11895b2 is described below

commit 3df11895b272df20640c866e4d7a48c86083d7ae
Author: Mihai Budiu <[email protected]>
AuthorDate: Mon May 26 18:43:36 2025 -0700

    [CALCITE-7043] Type inferred for SqlItemOperator has incorrect nullability
    
    Signed-off-by: Mihai Budiu <[email protected]>
---
 .../apache/calcite/sql/fun/SqlItemOperator.java    |  2 +-
 .../apache/calcite/test/TableInRootSchemaTest.java | 23 ++++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
index 9709f7359b..82551e8c00 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
@@ -227,7 +227,7 @@ private static SqlSingleOperandTypeChecker 
getChecker(SqlCallBinding callBinding
             + indexType + "'");
       }
       if (operandType.isNullable()) {
-        fieldType = typeFactory.createTypeWithNullability(fieldType, true);
+        fieldType = typeFactory.enforceTypeWithNullability(fieldType, true);
       }
       return fieldType;
     case ANY:
diff --git 
a/core/src/test/java/org/apache/calcite/test/TableInRootSchemaTest.java 
b/core/src/test/java/org/apache/calcite/test/TableInRootSchemaTest.java
index 99d742cd44..c4f333d386 100644
--- a/core/src/test/java/org/apache/calcite/test/TableInRootSchemaTest.java
+++ b/core/src/test/java/org/apache/calcite/test/TableInRootSchemaTest.java
@@ -192,8 +192,7 @@ protected TableWithNullableRowToplevel() {
     Statement statement = calciteConnection.createStatement();
     // Without the fix to this issue the Validator crashes with an 
AssertionFailure:
     // java.lang.RuntimeException: java.lang.AssertionError:
-    // Conversion to relational algebra failed to preserve datatypes:
-    // validated type:
+    // Conversion to relational algebra failed to preserve datatypes.
     ResultSet resultSet = statement.executeQuery("SELECT P['a'].K, P['a'].S 
FROM T");
     resultSet.close();
     statement.close();
@@ -210,11 +209,27 @@ protected TableWithNullableRowToplevel() {
     Statement statement = calciteConnection.createStatement();
     // Without the fix to this issue the Validator crashes with an 
AssertionFailure:
     // java.lang.RuntimeException: java.lang.AssertionError:
-    // Conversion to relational algebra failed to preserve datatypes:
-    // validated type:
+    // Conversion to relational algebra failed to preserve datatypes
     ResultSet resultSet = statement.executeQuery("SELECT T.P.K, T.Q.S, 
T.Q.S.L, T.Q.S.M FROM T");
     resultSet.close();
     statement.close();
     connection.close();
   }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7043";>[CALCITE-7043]
+   * Type inferred for SqlItemOperator has incorrect nullability</a>. */
+  @Test void testNullableRowTopLevel2() throws Exception {
+    Connection connection = DriverManager.getConnection("jdbc:calcite:");
+    CalciteConnection calciteConnection = 
connection.unwrap(CalciteConnection.class);
+    calciteConnection.getRootSchema().add("T", new 
TableWithNullableRowToplevel());
+    Statement statement = calciteConnection.createStatement();
+    // Without the fix to this issue the Validator crashes with an 
AssertionFailure:
+    // java.lang.RuntimeException: java.lang.AssertionError:
+    // Conversion to relational algebra failed to preserve datatypes.
+    ResultSet resultSet = statement.executeQuery("SELECT T.P[1], T.Q[1], 
T.Q[1][1] FROM T");
+    resultSet.close();
+    statement.close();
+    connection.close();
+  }
 }

Reply via email to