libenchao commented on code in PR #3189:
URL: https://github.com/apache/calcite/pull/3189#discussion_r1189294026


##########
core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java:
##########
@@ -122,8 +128,50 @@ static SqlReturnTypeInference returnTypeInference(boolean 
safe) {
   /** Derives the type of "CAST(expression AS targetType)". */
   public static RelDataType deriveType(RelDataTypeFactory typeFactory,
       RelDataType expressionType, RelDataType targetType, boolean safe) {
-    return typeFactory.createTypeWithNullability(targetType,
-        expressionType.isNullable() || safe);
+    return createTypeWithNullabilityFromExpr(typeFactory, expressionType, 
targetType, safe);
+  }
+
+  public static RelDataType 
createTypeWithNullabilityFromExpr(RelDataTypeFactory typeFactory,
+      RelDataType expressionType, RelDataType targetType, boolean safe) {
+    boolean isn = expressionType.isNullable() || safe;
+
+    if (isCollection(expressionType)) {
+      RelDataType expressionElementType = expressionType.getComponentType();
+      RelDataType targetElementType = targetType.getComponentType();
+      RelDataType newElementType =
+          createTypeWithNullabilityFromExpr(typeFactory, 
expressionElementType, targetElementType, false);

Review Comment:
   This is not what I meant to say. 
   
   Take a example, `ARRAY<VARCHAR NOT NULL> NOT NULL`, safe_cast it to 
`ARRAY<INT NULLABLE> NULLABLE`, what should the result be? IMO, the inner type 
should be `NULLABLE` because it may produce `null`s.



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