[fix](nereids)change the decimal's precision and scale for cast(xx as decimal) (#36540)
pick from master #36316 expression cast( xx as decimal )'s datatype maybe decimalv3 or decimalv2 depending on enable_decimal_conversion value in fe conf file. if enable_decimal_conversion is true, the datatype is decimalv3(9, 0), but the datatype was decimalv3(38, 9) in 2.0 releases. So this pr change the datatype same as 2.0 releases to keep the behavior consistent.
This commit is contained in:
@ -80,7 +80,7 @@ public class ExecutableFunctions {
|
||||
return new DoubleLiteral(Math.abs(literal.getValue()));
|
||||
}
|
||||
|
||||
@ExecFunction(name = "abs", argTypes = {"DECIMAL"}, returnType = "DECIMAL")
|
||||
@ExecFunction(name = "abs", argTypes = {"DECIMALV2"}, returnType = "DECIMALV2")
|
||||
public static Expression abs(DecimalLiteral literal) {
|
||||
return new DecimalLiteral(literal.getValue().abs());
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ public class NumericArithmetic {
|
||||
return new DoubleLiteral(result);
|
||||
}
|
||||
|
||||
@ExecFunction(name = "add", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
|
||||
@ExecFunction(name = "add", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2")
|
||||
public static Expression addDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
|
||||
BigDecimal result = first.getValue().add(second.getValue());
|
||||
return new DecimalLiteral(result);
|
||||
@ -368,7 +368,7 @@ public class NumericArithmetic {
|
||||
return new DoubleLiteral(result);
|
||||
}
|
||||
|
||||
@ExecFunction(name = "subtract", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
|
||||
@ExecFunction(name = "subtract", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2")
|
||||
public static Expression subtractDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
|
||||
BigDecimal result = first.getValue().subtract(second.getValue());
|
||||
return new DecimalLiteral(result);
|
||||
@ -539,7 +539,7 @@ public class NumericArithmetic {
|
||||
return new DoubleLiteral(result);
|
||||
}
|
||||
|
||||
@ExecFunction(name = "multiply", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
|
||||
@ExecFunction(name = "multiply", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2")
|
||||
public static Expression multiplyDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
|
||||
BigDecimal result = first.getValue().multiply(second.getValue());
|
||||
return new DecimalLiteral(result);
|
||||
@ -573,7 +573,7 @@ public class NumericArithmetic {
|
||||
/**
|
||||
* Executable arithmetic functions divide
|
||||
*/
|
||||
@ExecFunction(name = "divide", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
|
||||
@ExecFunction(name = "divide", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2")
|
||||
public static Expression divideDecimal(DecimalLiteral first, DecimalLiteral second) {
|
||||
if (first.getValue().compareTo(BigDecimal.ZERO) == 0) {
|
||||
return new NullLiteral(first.getDataType());
|
||||
|
||||
@ -19,6 +19,7 @@ package org.apache.doris.nereids.types;
|
||||
|
||||
import org.apache.doris.catalog.ScalarType;
|
||||
import org.apache.doris.catalog.Type;
|
||||
import org.apache.doris.common.Config;
|
||||
import org.apache.doris.nereids.annotation.Developing;
|
||||
import org.apache.doris.nereids.exceptions.AnalysisException;
|
||||
import org.apache.doris.nereids.parser.NereidsParser;
|
||||
@ -142,7 +143,11 @@ public abstract class DataType {
|
||||
// NOTICE, maybe convert to decimalv3, so do not truc here.
|
||||
switch (types.size()) {
|
||||
case 1:
|
||||
dataType = DecimalV2Type.CATALOG_DEFAULT;
|
||||
if (Config.enable_decimal_conversion) {
|
||||
return DecimalV3Type.createDecimalV3Type(38, 9);
|
||||
} else {
|
||||
dataType = DecimalV2Type.CATALOG_DEFAULT;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
dataType = DecimalV2Type.createDecimalV2TypeWithoutTruncate(
|
||||
|
||||
Reference in New Issue
Block a user