pfzhan commented on code in PR #3326:
URL: https://github.com/apache/calcite/pull/3326#discussion_r1280034460
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java:
##########
@@ -625,7 +627,10 @@ private static Expression checkExpressionPadTruncate(
default:
return operand;
}
-
+ case DECIMAL:
+ return sourceType.getScale() == targetType.getScale()
+ ? operand
+ : adjustDecimalScale(targetType.getScale(), operand);
Review Comment:
The method `EnumUtils#convert(Expression operand, Type fromType, Type
toType)` indeed transfers the type, but for BigDecimal it just new a instance
of the operand.Since existing methods do not pass target scale info into this
method, there is no way to deal with scale in `EnumUtils#convert`.
`Expression translateCast( RelDataType sourceType, RelDataType targetType,
Expression operand, boolean safe) {
Expression convert = getConvertExpression(sourceType, targetType,
operand);
Expression convert2 = checkExpressionPadTruncate(convert, sourceType,
targetType);
Expression convert3 = expressionHandlingSafe(convert2, safe);
return scaleIntervalToNumber(sourceType, targetType, convert3);
}`
This method deals with type casting, the expression returned by
`getConvertExpression` can be seen as not dealing with scale, and
`checkExpressionPadTruncate` similarly deals with scale for char/timestamp
etc., so it seems a good place to deal with the scale of BigDecimal. Besides,
we know the scale information of targetType and sourceType at this point, so
it's easy to compare and set the target scale.
--
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]