mihaibudiu commented on code in PR #3501:
URL: https://github.com/apache/calcite/pull/3501#discussion_r1383700723


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10497,6 +10497,29 @@ private static void 
checkArrayConcatAggFuncFails(SqlOperatorFixture t) {
         "[1         , 2         , Hi        , null]", "CHAR(10) ARRAY NOT 
NULL");
   }
 
+  /**
+   * Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6091";>[CALCITE-6091]
+   * Char that in array or map is truncated if CASE WHEN statement contains 
null</a>.
+   */
+  @Test void testTruncatedCharInCaseWhen() {
+    final SqlOperatorFixture fixture = fixture().withLibrary(SqlLibrary.SPARK);
+    fixture.check("select case "
+            + "when true then array('abc') "
+            + "when false then array('d') "
+            + "else null "

Review Comment:
   The type produced `CHAR(3) NOT NULL ARRAY` suggests that the expression is 
simplified before type inference.
   If the expression wasn't simplified the type should be `VARCHAR ARRAY`.
   But probably the simplification is done after type inference, so that's why 
this test works.
   



##########
core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java:
##########
@@ -262,15 +262,21 @@ private RelDataType createStructType(
       final List<RelDataType> types, SqlTypeName sqlTypeName) {
     assert sqlTypeName == SqlTypeName.ARRAY || sqlTypeName == 
SqlTypeName.MULTISET;
     boolean isNullable = false;
+    final List<RelDataType> notNullTypes = new ArrayList<>();
     for (RelDataType type : types) {
+      if (SqlTypeUtil.isNull(type)) {
+        isNullable = true;
+        continue;
+      }
       if (type.getComponentType() == null) {
         return null;
       }
+      notNullTypes.add(type);
       isNullable |= type.isNullable();
     }
     final RelDataType type =
         leastRestrictive(
-            Util.transform(types,
+            Util.transform(notNullTypes,

Review Comment:
   My feeling was that `leastRestrictive` should be fixed instead to deal 
correctly with the NULL type.
   So this solution is fine, but if leastRestrictive can be made more general, 
other users could benefit.
   



-- 
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]

Reply via email to