branch-2.1: [fix](nereids) fix compare with long min for simplify comparison rule (#44922)
This commit is contained in:
@ -281,7 +281,8 @@ public class SimplifyComparisonPredicate extends AbstractExpressionRewriteRule i
|
||||
private static Expression processIntegerDecimalLiteralComparison(
|
||||
ComparisonPredicate comparisonPredicate, Expression left, BigDecimal literal) {
|
||||
// we only process isIntegerLikeType, which are tinyint, smallint, int, bigint
|
||||
if (literal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0) {
|
||||
if (literal.compareTo(new BigDecimal(Long.MIN_VALUE)) >= 0
|
||||
&& literal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0) {
|
||||
literal = literal.stripTrailingZeros();
|
||||
if (literal.scale() > 0) {
|
||||
if (comparisonPredicate instanceof EqualTo) {
|
||||
@ -321,9 +322,10 @@ public class SimplifyComparisonPredicate extends AbstractExpressionRewriteRule i
|
||||
}
|
||||
|
||||
private static IntegerLikeLiteral convertDecimalToIntegerLikeLiteral(BigDecimal decimal) {
|
||||
Preconditions.checkArgument(
|
||||
decimal.scale() <= 0 && decimal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0,
|
||||
"decimal literal must have 0 scale and smaller than Long.MAX_VALUE");
|
||||
Preconditions.checkArgument(decimal.scale() <= 0
|
||||
&& decimal.compareTo(new BigDecimal(Long.MIN_VALUE)) >= 0
|
||||
&& decimal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0,
|
||||
"decimal literal must have 0 scale and in range [Long.MIN_VALUE, Long.MAX_VALUE]");
|
||||
long val = decimal.longValue();
|
||||
if (val >= Byte.MIN_VALUE && val <= Byte.MAX_VALUE) {
|
||||
return new TinyIntLiteral((byte) val);
|
||||
|
||||
Reference in New Issue
Block a user