pfzhan commented on code in PR #3326:
URL: https://github.com/apache/calcite/pull/3326#discussion_r1280060417
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java:
##########
@@ -774,10 +779,15 @@ public static Expression translateLiteral(
return Expressions.constant(bd, javaClass);
}
assert javaClass == BigDecimal.class;
- return Expressions.new_(BigDecimal.class,
- Expressions.constant(
+ Expression expression =
+ Expressions.new_(
+ BigDecimal.class, constant(
requireNonNull(bd,
() -> "value for " + literal).toString()));
+ if (type.getScale() != bd.scale()) {
+ expression = adjustDecimalScale(type.getScale(), expression);
+ }
+ return expression;
Review Comment:
when invoke RexBuilder#canRemoveCastFromLiteral the call, for example
`cast(-0.1 as decimal(19, 0))` returns true, then it will be translate to
-0.1:BigDeciaml(19, 0) as a literal.

However, the BigDecimal gives scale=1. So we should change the scale to the
correct one.
If we run the `CalciteSqlOperatorTest.java` we will found this problem, but
the agg.iq, misc.iq, and the expected values of `SqlOperatorTest.java` are
wrong, so this issue is being ignored.
--
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]