danny0405 commented on a change in pull request #1381: [CALCITE-3245] 
CompileException in Janino when a query contains a division between a Double 
and a BigDecimal
URL: https://github.com/apache/calcite/pull/1381#discussion_r314602262
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
 ##########
 @@ -2278,9 +2278,12 @@ public Expression implement(
 
       final Type returnType =
           translator.typeFactory.getJavaClass(call.getType());
-      return Types.castIfNecessary(returnType,
-          Expressions.makeBinary(expressionType, expressions.get(0),
-              expressions.get(1)));
+      final Expression result = Expressions.makeBinary(expressionType,
+          expressions.get(0), expressions.get(1));
+      if (returnType == BigDecimal.class) {
+        return RexToLixTranslator.convert(result, returnType);
+      }
+      return Types.castIfNecessary(returnType, result);
     }
 
 
 Review comment:
   I don't think `RexToLixTranslator.convert`, 
`RexToLixTranslator.translateCast` and `Types.castIfNecessary` have any 
function overlaps, the first 2 are purely about the expression translate, they 
just produce the expression you want, but `Types.castIfNecessary` contains 
logic to decide if the is any necessity to do the cast, that is why i suggest 
you to move the logic.
   
   If you think i'm wrong or other people can do it better, feel free to ignore 
this.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to