DonnyZone 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_r314681378
##########
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:
@danny0405 Thanks for discussion and suggestion, Danny. It is great helpful
to me to make it more clear.
Current now, I'm a bit of confusing about the semantic differences between
`cast `and `convert`. It seems in `Types.castIfNecessary` also conduct some
converting work.
For instance, from **_Integer_** to **_int_**, the cast will call
`Expressions.unbox`. Meanwhile, we can also do it with
`RexToLixTranslator.convert`. So I am curious about the design intention, but I
can't find some documents.
----------------------------------------------------------------
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