Skip to content

Commit

Permalink
[fix](nereids) fix wrong result precision for add/sub
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktengg committed Oct 26, 2023
1 parent 2229d82 commit 7b3f76f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public Expression withChildren(List<Expression> children) {

@Override
public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1, DecimalV3Type t2) {
return (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false);
DecimalV3Type decimalV3Type = (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false);
return (DecimalV3Type) DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1,
decimalV3Type.getScale());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public Expression withChildren(List<Expression> children) {

@Override
public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1, DecimalV3Type t2) {
return (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false);
DecimalV3Type decimalV3Type = (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false);
return (DecimalV3Type) DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1,
decimalV3Type.getScale());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,12 @@ public void testDecimalArithmetic() {
new DecimalV3Literal(new BigDecimal("123.45")));
expression = TypeCoercionUtils.processBinaryArithmetic(add);
Assertions.assertEquals(expression.child(0),
new Cast(multiply.child(0), DecimalV3Type.createDecimalV3Type(9, 3)));
new Cast(multiply.child(0), DecimalV3Type.createDecimalV3Type(10, 3)));

Subtract sub = new Subtract(new DecimalLiteral(new BigDecimal("987654.321")),
new DecimalV3Literal(new BigDecimal("123.45")));
expression = TypeCoercionUtils.processBinaryArithmetic(sub);
Assertions.assertEquals(expression.child(0),
new Cast(multiply.child(0), DecimalV3Type.createDecimalV3Type(9, 3)));
new Cast(multiply.child(0), DecimalV3Type.createDecimalV3Type(10, 3)));
}
}

0 comments on commit 7b3f76f

Please sign in to comment.