Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](Nereids) simplify comparison predicate do wrong cast #44054

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ private static Expression processDecimalV3TypeCoercion(ComparisonPredicate compa
left = cast.child();
DecimalV3Literal literal = (DecimalV3Literal) right;
if (left.getDataType().isDecimalV3Type()) {
if (((DecimalV3Type) left.getDataType())
.getScale() < ((DecimalV3Type) literal.getDataType()).getScale()) {
DecimalV3Type leftType = (DecimalV3Type) left.getDataType();
DecimalV3Type literalType = (DecimalV3Type) literal.getDataType();
if (leftType.getScale() < literalType.getScale()) {
int toScale = ((DecimalV3Type) left.getDataType()).getScale();
if (comparisonPredicate instanceof EqualTo) {
try {
return TypeCoercionUtils.processComparisonPredicate((ComparisonPredicate)
comparisonPredicate.withChildren(left,
new DecimalV3Literal((DecimalV3Type) left.getDataType(),
literal.getValue().setScale(toScale, RoundingMode.UNNECESSARY))));
comparisonPredicate.withChildren(left, new DecimalV3Literal(
literal.getValue().setScale(toScale, RoundingMode.UNNECESSARY))));
} catch (ArithmeticException e) {
if (left.nullable()) {
// TODO: the ideal way is to return an If expr like:
Expand All @@ -255,9 +255,8 @@ private static Expression processDecimalV3TypeCoercion(ComparisonPredicate compa
} else if (comparisonPredicate instanceof NullSafeEqual) {
try {
return TypeCoercionUtils.processComparisonPredicate((ComparisonPredicate)
comparisonPredicate.withChildren(left,
new DecimalV3Literal((DecimalV3Type) left.getDataType(),
literal.getValue().setScale(toScale, RoundingMode.UNNECESSARY))));
comparisonPredicate.withChildren(left, new DecimalV3Literal(
literal.getValue().setScale(toScale, RoundingMode.UNNECESSARY))));
} catch (ArithmeticException e) {
return BooleanLiteral.of(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,17 @@ void testDecimalV3Literal() {
rewrittenExpression.child(0).getDataType());
Assertions.assertInstanceOf(DecimalV3Literal.class, rewrittenExpression.child(1));
Assertions.assertEquals(new BigDecimal("12.35"), ((DecimalV3Literal) rewrittenExpression.child(1)).getValue());

// left's child range smaller than right literal
leftChild = new DecimalV3Literal(new BigDecimal("1234.12"));
left = new Cast(leftChild, DecimalV3Type.createDecimalV3Type(10, 5));
right = new DecimalV3Literal(new BigDecimal("12345.12000"));
expression = new EqualTo(left, right);
rewrittenExpression = executor.rewrite(expression, context);
Assertions.assertInstanceOf(Cast.class, rewrittenExpression.child(0));
Assertions.assertEquals(DecimalV3Type.createDecimalV3Type(7, 2),
rewrittenExpression.child(0).getDataType());
Assertions.assertInstanceOf(DecimalV3Literal.class, rewrittenExpression.child(1));
Assertions.assertEquals(new BigDecimal("12345.12"), ((DecimalV3Literal) rewrittenExpression.child(1)).getValue());
}
}
Loading