Skip to content

Commit

Permalink
fix failed case
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 committed Dec 21, 2023
1 parent 167d61b commit 41e08a8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
import org.apache.doris.nereids.types.DecimalV2Type;
import org.apache.doris.nereids.types.DecimalV3Type;

import java.math.BigDecimal;
Expand Down Expand Up @@ -201,7 +200,6 @@ public static Expression addDoubleDouble(DoubleLiteral first, DoubleLiteral seco
@ExecFunction(name = "add", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
public static Expression addDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().add(second.getValue());
DecimalV2Type.validateDecimalV2Type(result);
return new DecimalLiteral(result);
}

Expand Down Expand Up @@ -373,7 +371,6 @@ public static Expression subtractDoubleDouble(DoubleLiteral first, DoubleLiteral
@ExecFunction(name = "subtract", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
public static Expression subtractDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().subtract(second.getValue());
DecimalV2Type.validateDecimalV2Type(result);
return new DecimalLiteral(result);
}

Expand Down Expand Up @@ -545,7 +542,6 @@ public static Expression multiplyDoubleDouble(DoubleLiteral first, DoubleLiteral
@ExecFunction(name = "multiply", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
public static Expression multiplyDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().multiply(second.getValue());
DecimalV2Type.validateDecimalV2Type(result);
return new DecimalLiteral(result);
}

Expand Down Expand Up @@ -583,7 +579,6 @@ public static Expression divideDecimal(DecimalLiteral first, DecimalLiteral seco
return new NullLiteral(first.getDataType());
}
BigDecimal result = first.getValue().divide(second.getValue());
DecimalV2Type.validateDecimalV2Type(result);
return new DecimalLiteral(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public static void checkPrecisionAndScale(int precision, int scale, BigDecimal v
int realScale = value.scale();
boolean valid = true;
if (precision != -1 && scale != -1) {
if (precision < realPrecision || scale < realScale) {
if (precision < realPrecision || scale < realScale
|| realPrecision - realScale > DecimalV2Type.MAX_PRECISION - DecimalV2Type.MAX_SCALE) {
valid = false;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,6 @@ public static DecimalV2Type createDecimalV2Type(BigDecimal bigDecimal) {
return createDecimalV2Type(precision, scale);
}

/**
* validate DecimalV2Type can hold bigDecimal literal, throw exception if overflows
*/
public static void validateDecimalV2Type(BigDecimal bigDecimal) {
int precision = org.apache.doris.analysis.DecimalLiteral.getBigDecimalPrecision(bigDecimal);
int scale = org.apache.doris.analysis.DecimalLiteral.getBigDecimalScale(bigDecimal);

Preconditions.checkArgument(precision > 0 && precision <= MAX_PRECISION,
"precision should in (0, " + MAX_PRECISION + "], but real precision is "
+ precision);
Preconditions.checkArgument(scale >= 0 && scale <= MAX_SCALE,
"scale should in (0, " + MAX_SCALE + "], but real precision is " + scale);
int integerPart = precision - scale;
Preconditions.checkArgument(integerPart >= 0 && integerPart <= MAX_PRECISION - MAX_SCALE,
"precision - scale should in (0, " + integerPart + "], but real precision is "
+ integerPart);
}

/**
* create DecimalV2Type with appropriate scale and precision, not truncate to MAX_PRECISION, MAX_SCALE.
*/
Expand Down

0 comments on commit 41e08a8

Please sign in to comment.