[fix](Nereids) tablet prune wrong when decimal value scale is nagtive (#37889) (#38013)

pick from master #37889

we use unscaled value of BigDecimal in tablet prune. So we need to
ensure BigDecimal's precision and scale is same with the literal
contains it.
This commit is contained in:
morrySnow
2024-07-17 20:12:14 +08:00
committed by GitHub
parent 7180290d68
commit 78d51ca320
7 changed files with 53 additions and 5 deletions

View File

@ -29,6 +29,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
/**
@ -72,10 +73,15 @@ public class SimplifyDecimalV3Comparison implements ExpressionPatternRuleFactory
BigDecimal trailingZerosValue = right.getValue().stripTrailingZeros();
int scale = org.apache.doris.analysis.DecimalLiteral.getBigDecimalScale(trailingZerosValue);
int precision = org.apache.doris.analysis.DecimalLiteral.getBigDecimalPrecision(trailingZerosValue);
try {
trailingZerosValue = trailingZerosValue.setScale(scale, RoundingMode.UNNECESSARY);
} catch (ArithmeticException e) {
return cp;
}
Expression castChild = left.child();
Preconditions.checkState(castChild.getDataType() instanceof DecimalV3Type);
DecimalV3Type leftType = (DecimalV3Type) castChild.getDataType();
if (scale <= leftType.getScale() && precision - scale <= leftType.getPrecision() - leftType.getScale()) {
// precision and scale of literal all smaller than left, we don't need the cast
DecimalV3Literal newRight = new DecimalV3Literal(