[fix](round) Fix incorrect decimal scale inference in round functions (#34471)

* FIX NEEDED

* FORMAT

* FORMAT

* FIX TEST
This commit is contained in:
zhiqiang
2024-05-10 16:09:46 +08:00
committed by yiguolei
parent 0a79c547ff
commit 58c19e33b3
4 changed files with 237 additions and 42 deletions

View File

@ -37,9 +37,12 @@ public interface ComputePrecisionForRound extends ComputePrecision {
Expression floatLength = getArgument(1);
int scale;
if (floatLength.isLiteral() || (floatLength instanceof Cast && floatLength.child(0).isLiteral()
// If scale arg is an integer literal, or it is a cast(Integer as Integer)
// then we will try to use its value as result scale
// In any other cases, we will make sure result decimal has same scale with input.
if ((floatLength.isLiteral() && floatLength.getDataType() instanceof Int32OrLessType)
|| (floatLength instanceof Cast && floatLength.child(0).isLiteral()
&& floatLength.child(0).getDataType() instanceof Int32OrLessType)) {
// Scale argument is a literal or cast from other literal
if (floatLength instanceof Cast) {
scale = ((IntegerLikeLiteral) floatLength.child(0)).getIntValue();
} else {