Anthrino commented on code in PR #3677:
URL: https://github.com/apache/calcite/pull/3677#discussion_r1554345497


##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java:
##########
@@ -469,34 +349,48 @@ private Expression getConvertExpression(
       final SqlIntervalQualifier interval =
           sourceType.getIntervalQualifier();
       switch (sourceType.getSqlTypeName()) {
+      // If format string is supplied, return formatted date/time/timestamp
       case DATE:
-        return RexImpTable.optimize2(operand,
-            Expressions.call(BuiltInMethod.UNIX_DATE_TO_STRING.method,
-                operand));
+        return RexImpTable.optimize2(operand, 
Expressions.isConstantNull(format)
+            ? Expressions.call(BuiltInMethod.UNIX_DATE_TO_STRING.method, 
operand)
+            : Expressions.call(
+                Expressions.new_(
+                    BuiltInMethod.FORMAT_DATE.method.getDeclaringClass()),
+                BuiltInMethod.FORMAT_DATE.method, format, operand));
 
       case TIME:
-        return RexImpTable.optimize2(operand,
-            Expressions.call(BuiltInMethod.UNIX_TIME_TO_STRING.method,
-                operand));
+        return RexImpTable.optimize2(operand, 
Expressions.isConstantNull(format)

Review Comment:
   Not exactly, we could actually only move the `RexImpTable.optimize2()` call 
outside the switch, but the specific method called to evaluate the CAST depends 
on the from and to cast data types, and with this change also if there is a 
`FORMAT` present. So the number of lines would still look the same could move 
out one level of nesting with that optimize call and return statements outside. 
Does that seem like a better pattern?



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