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_r314571351
##########
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 review! To the best of my knowledge, data type
conversion are implemented in many places (`Types.castIfNecessary`,
`RexToLixTranslator.convert`, `RexToLixTranslator.translateCast`, etc.) with
some overlaps. We can move this logic into `Types.castIfNecessary`, but it will
bring more redundancy, because the logic has been implemented in
`RexToLixTranslator.convert` already.
Therefore, this PR handle it in a case-by-case way. I ever tried to unify
these functions and combine them into one. But I do not know whether it is an
appropriate way. Maybe @zabetak , @julianhyde and @vlsi can provide some
helpful advices.
----------------------------------------------------------------
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