raminqaf commented on code in PR #29202:
URL: https://github.com/apache/flink/pull/29202#discussion_r4064031402


##########
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java:
##########
@@ -159,6 +179,19 @@ private static RelDataType 
createTypeWithNullabilityFromExpr(
             boolean safe) {
         boolean isNullable = expressionType.isNullable() || safe;
 
+        if (targetType.getSqlTypeName() == SqlTypeName.VARIANT) {
+            // A variant can be cast from any other type, and it inherits
+            // the nullability of the source.
+            // Note that the order of this test and the next one is important.
+            return typeFactory.createTypeWithNullability(targetType, 
expressionType.isNullable());
+        }
+
+        if (expressionType.getSqlTypeName() == SqlTypeName.VARIANT) {
+            // A variant can be cast to any other type, but the result
+            // is always nullable, like in the case of a safe cast.
+            return typeFactory.createTypeWithNullability(targetType, true);

Review Comment:
   One thing that got confused is that we have hardcoded nullability here. So 
if I write something like:
   ```sql
   CAST(PARSE_JSON('42') AS TINYINT NOT NULL)
   ```
   
   I would get a nullable TINYINT. Is this the correct behavior we are seeking?



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