lowka commented on code in PR #7768:
URL: https://github.com/apache/ignite-3/pull/7768#discussion_r2945718765


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/ConverterUtils.java:
##########
@@ -221,10 +221,18 @@ private static Expression convertToTimestamp(Expression 
operand, RelDataType tar
             methodName = "toTimestampLtzExact";
         }
 
+        // Box primitive operand to ensure the null-safe Object overload is 
selected,
+        // and RexImpTable builds a correct condition in genValueStatement() 
method
+        // if type is long then the condition: is input_isNull ? 0 : 
<toTimestampExact>
+        // Otherwise, when type is Long, the condition is is input_isNull ? 
null : <toTimestampExact>
+        Expression safeOperand = Primitive.is(operand.getType())

Review Comment:
   After some digging, I have come to the conclusion that each for each CAST  
X(non-nullable) -> Y(nullable) the code that performs the conversion should be 
manually wrapped in `input != null ? null : <expr>`.
   
   There are plenty of evidence to support this in `EnumUtils' `public static 
Expression convert(Expression operand, Type fromType,  Type toType)`
   
   ```
   // else if (fromType == BigDecimal.class) {
           // E.g. from "BigDecimal" to "String"
           // Generate "SqlFunctions.toString(x)"
           return Expressions.condition(
               Expressions.equal(operand, RexImpTable.NULL_EXPR),
               RexImpTable.NULL_EXPR,
               Expressions.call(
                   SqlFunctions.class,
                   "toString",
                   operand));
         }
   
   ...
   
    // Generate "x == null ? null : UnsignedType.toULong(x)"
           return Expressions.condition(
               Expressions.equal(operand, RexImpTable.NULL_EXPR),
               RexImpTable.NULL_EXPR,
               Expressions.call(
                   UnsignedType.class,
                   functionName,
                   operand));
   ```



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