danny0405 commented on a change in pull request #1507: [CALCITE-3414] In 
calcite-core, use RexToLixTranslator.convert for type conversion code 
generation uniformly
URL: https://github.com/apache/calcite/pull/1507#discussion_r337005857
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
 ##########
 @@ -1143,14 +1156,20 @@ public static Expression convert(Expression operand, 
Type fromType,
                 "toString",
                 operand));
       } else {
-        // E.g. from "BigDecimal" to "String"
-        // Generate "x == null ? null : x.toString()"
-        return Expressions.condition(
-            Expressions.equal(operand, RexImpTable.NULL_EXPR),
-            RexImpTable.NULL_EXPR,
-            Expressions.call(
-                operand,
-                "toString"));
+        Expression result;
+        try {
+          // Try to call "toString()" method
+          // E.g. from "Integer" to "String"
+          // Generate "x == null ? null : x.toString()"
+          result = Expressions.condition(
+              Expressions.equal(operand, RexImpTable.NULL_EXPR),
+              RexImpTable.NULL_EXPR,
+              Expressions.call(operand, "toString"));
+        } catch (Exception e) {
+          // No "toString()" method, fall through to (String)x
 
 Review comment:
   Although the operand type class of `SqlFunctions.lesser(String.class, 
String.class)` does not implement `toString` method, the object should have 
implement the `toString` method, because the java Object already has that, did 
you mean the operand object is not a java Object ?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to