[feature](decimal) support decimal256 when creating table (#26308)

This commit is contained in:
TengJianPing
2023-11-08 15:21:01 +08:00
committed by GitHub
parent be7d49cb9f
commit a3666aa87e
59 changed files with 6669 additions and 260 deletions

View File

@ -30,6 +30,7 @@ import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.TreeNode;
import org.apache.doris.nereids.util.Utils;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TExprNode;
import com.google.common.base.Joiner;
@ -361,7 +362,8 @@ public class AnalyticExpr extends Expr {
Expr rangeExpr = boundary.getExpr();
if (!Type.isImplicitlyCastable(
rangeExpr.getType(), orderByElements.get(0).getExpr().getType(), false)) {
rangeExpr.getType(), orderByElements.get(0).getExpr().getType(), false,
SessionVariable.getEnableDecimal256())) {
throw new AnalysisException(
"The value expression of a PRECEDING/FOLLOWING clause of a RANGE window must "
+ "be implicitly convertible to the ORDER BY expression's type: "

View File

@ -45,6 +45,7 @@ import org.apache.doris.planner.AnalyticEvalNode;
import org.apache.doris.planner.PlanNode;
import org.apache.doris.planner.RuntimeFilter;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.rewrite.BetweenToCompoundRule;
import org.apache.doris.rewrite.CompoundPredicateWriteRule;
import org.apache.doris.rewrite.EliminateUnnecessaryFunctions;
@ -2155,7 +2156,8 @@ public class Analyzer {
if (lastCompatibleType == null) {
newCompatibleType = expr.getType();
} else {
newCompatibleType = Type.getAssignmentCompatibleType(lastCompatibleType, expr.getType(), false);
newCompatibleType = Type.getAssignmentCompatibleType(
lastCompatibleType, expr.getType(), false, SessionVariable.getEnableDecimal256());
}
if (!newCompatibleType.isValid()) {
throw new AnalysisException(String.format(
@ -2177,15 +2179,16 @@ public class Analyzer {
Type compatibleType = exprs.get(0).getType();
for (int i = 1; i < exprs.size(); ++i) {
exprs.get(i).analyze(this);
boolean enableDecimal256 = SessionVariable.getEnableDecimal256();
if (compatibleType.isDateV2() && exprs.get(i) instanceof StringLiteral
&& ((StringLiteral) exprs.get(i)).canConvertToDateType(compatibleType)) {
// If string literal can be converted to dateV2, we use datev2 as the compatible type
// instead of datetimev2.
} else if (exprs.get(i).isConstantImpl()) {
exprs.get(i).compactForLiteral(compatibleType);
compatibleType = Type.getCmpType(compatibleType, exprs.get(i).getType());
compatibleType = Type.getCmpType(compatibleType, exprs.get(i).getType(), enableDecimal256);
} else {
compatibleType = Type.getCmpType(compatibleType, exprs.get(i).getType());
compatibleType = Type.getCmpType(compatibleType, exprs.get(i).getType(), enableDecimal256);
}
}
if (compatibleType.equals(Type.VARCHAR)) {

View File

@ -31,6 +31,7 @@ import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.io.Text;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TExprOpcode;
@ -111,7 +112,8 @@ public class ArithmeticExpr extends Expr {
for (int j = 0; j < Type.getNumericTypes().size(); j++) {
Type t2 = Type.getNumericTypes().get(j);
Type retType = Type.getNextNumType(Type.getAssignmentCompatibleType(t1, t2, false));
// For old planner, set enableDecimal256 to false to keep the original behaviour
Type retType = Type.getNextNumType(Type.getAssignmentCompatibleType(t1, t2, false, false));
NullableMode mode = retType.isDecimalV3() ? NullableMode.CUSTOM : NullableMode.DEPEND_ON_ARGUMENT;
functionSet.addBuiltin(ScalarFunction.createBuiltinOperator(
Operator.MULTIPLY.getName(), Lists.newArrayList(t1, t2), retType, mode));
@ -197,13 +199,14 @@ public class ArithmeticExpr extends Expr {
for (int j = 0; j < Type.getIntegerTypes().size(); j++) {
Type t2 = Type.getIntegerTypes().get(j);
// For old planner, set enableDecimal256 to false to keep the original behaviour
functionSet.addBuiltin(ScalarFunction.createBuiltinOperator(
Operator.INT_DIVIDE.getName(), Lists.newArrayList(t1, t2),
Type.getAssignmentCompatibleType(t1, t2, false),
Type.getAssignmentCompatibleType(t1, t2, false, false),
Function.NullableMode.ALWAYS_NULLABLE));
functionSet.addBuiltin(ScalarFunction.createBuiltinOperator(
Operator.MOD.getName(), Lists.newArrayList(t1, t2),
Type.getAssignmentCompatibleType(t1, t2, false),
Type.getAssignmentCompatibleType(t1, t2, false, false),
Function.NullableMode.ALWAYS_NULLABLE));
}
}
@ -401,7 +404,7 @@ public class ArithmeticExpr extends Expr {
t1 = Type.TINYINT;
t2 = Type.TINYINT;
}
commonType = Type.getAssignmentCompatibleType(t1, t2, false);
commonType = Type.getAssignmentCompatibleType(t1, t2, false, SessionVariable.getEnableDecimal256());
if (commonType.getPrimitiveType().ordinal() > PrimitiveType.LARGEINT.ordinal()) {
commonType = Type.BIGINT;
}

View File

@ -53,7 +53,7 @@ public class ArrayLiteral extends LiteralExpr {
if (itemType == Type.NULL) {
itemType = expr.getType();
} else {
itemType = Type.getAssignmentCompatibleType(itemType, expr.getType(), false);
itemType = Type.getAssignmentCompatibleType(itemType, expr.getType(), false, false);
}
if (expr.isNullable()) {

View File

@ -33,6 +33,7 @@ import org.apache.doris.common.Pair;
import org.apache.doris.common.Reference;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TExprOpcode;
@ -447,7 +448,8 @@ public class BinaryPredicate extends Predicate implements Writable {
return Type.STRING;
}
if (t1 == PrimitiveType.BIGINT && t2 == PrimitiveType.BIGINT) {
return Type.getAssignmentCompatibleType(getChild(0).getType(), getChild(1).getType(), false);
return Type.getAssignmentCompatibleType(getChild(0).getType(), getChild(1).getType(), false,
SessionVariable.getEnableDecimal256());
}
if ((t1 == PrimitiveType.BIGINT && t2 == PrimitiveType.DECIMALV2)
|| (t2 == PrimitiveType.BIGINT && t1 == PrimitiveType.DECIMALV2)
@ -480,7 +482,8 @@ public class BinaryPredicate extends Predicate implements Writable {
if ((t1.isDecimalV3Type() && !t2.isStringType() && !t2.isFloatingPointType())
|| (t2.isDecimalV3Type() && !t1.isStringType() && !t1.isFloatingPointType())) {
return Type.getAssignmentCompatibleType(getChild(0).getType(), getChild(1).getType(), false);
return Type.getAssignmentCompatibleType(getChild(0).getType(), getChild(1).getType(), false,
SessionVariable.getEnableDecimal256());
}
return Type.DOUBLE;

View File

@ -27,6 +27,7 @@ import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.InvalidFormatException;
import org.apache.doris.nereids.util.DateUtils;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TDateLiteral;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
@ -716,7 +717,7 @@ public class DateLiteral extends LiteralExpr {
long value = getYear() * 1000 + getMonth() * 100 + getDay();
return new IntLiteral(value, Type.BIGINT);
} else {
if (Type.isImplicitlyCastable(this.type, targetType, true)) {
if (Type.isImplicitlyCastable(this.type, targetType, true, SessionVariable.getEnableDecimal256())) {
return new CastExpr(targetType, this);
}
}

View File

@ -213,6 +213,7 @@ public class DecimalLiteral extends LiteralExpr {
buffer.putLong(value.unscaledValue().longValue());
break;
case DECIMAL128:
case DECIMAL256:
LargeIntLiteral tmp = new LargeIntLiteral(value.unscaledValue());
return tmp.getHashValue(type);
default:

View File

@ -40,6 +40,7 @@ import org.apache.doris.common.TreeNode;
import org.apache.doris.common.io.Writable;
import org.apache.doris.nereids.util.Utils;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.rewrite.mvrewrite.MVExprEquivalent;
import org.apache.doris.statistics.ExprStats;
import org.apache.doris.thrift.TExpr;
@ -1059,7 +1060,7 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
}
assignmentCompatibleType = assignmentCompatibleType.isInvalid() ? children.get(i).type
: ScalarType.getAssignmentCompatibleType(assignmentCompatibleType, children.get(i).type,
true);
true, SessionVariable.getEnableDecimal256());
}
return assignmentCompatibleType;
}

View File

@ -41,6 +41,7 @@ import org.apache.doris.common.ErrorReport;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.nereids.util.Utils;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
@ -1238,6 +1239,7 @@ public class FunctionCallExpr extends Expr {
}
private void analyzeArrayFunction(Analyzer analyzer) throws AnalysisException {
boolean enableDecimal256 = SessionVariable.getEnableDecimal256();
if (fnName.getFunction().equalsIgnoreCase("array_distinct")
|| fnName.getFunction().equalsIgnoreCase("array_max")
|| fnName.getFunction().equalsIgnoreCase("array_min")
@ -1254,7 +1256,8 @@ public class FunctionCallExpr extends Expr {
Type[] childTypes = collectChildReturnTypes();
Type compatibleType = childTypes[0];
for (int i = 1; i < childTypes.length; ++i) {
compatibleType = Type.getAssignmentCompatibleType(compatibleType, childTypes[i], true);
compatibleType = Type.getAssignmentCompatibleType(compatibleType, childTypes[i], true,
enableDecimal256);
if (compatibleType == Type.INVALID) {
throw new AnalysisException(getFunctionNotFoundError(collectChildReturnTypes()));
}
@ -1291,7 +1294,8 @@ public class FunctionCallExpr extends Expr {
}
Type compatibleType = ((ArrayType) childTypes[0]).getItemType();
for (int i = 1; i < childTypes.length; ++i) {
compatibleType = Type.getAssignmentCompatibleType(compatibleType, childTypes[i], true);
compatibleType = Type.getAssignmentCompatibleType(compatibleType, childTypes[i], true,
enableDecimal256);
if (compatibleType == Type.INVALID) {
throw new AnalysisException(getFunctionNotFoundError(collectChildReturnTypes()));
}
@ -1391,6 +1395,7 @@ public class FunctionCallExpr extends Expr {
analyzeArrayFunction(analyzer);
boolean enableDecimal256 = SessionVariable.getEnableDecimal256();
if (fnName.getFunction().equalsIgnoreCase("sum")) {
if (this.children.isEmpty()) {
throw new AnalysisException("The " + fnName + " function must has one input param");
@ -1403,7 +1408,7 @@ public class FunctionCallExpr extends Expr {
Type compatibleType = this.children.get(0).getType();
for (int i = 1; i < this.children.size(); ++i) {
Type type = this.children.get(i).getType();
compatibleType = Type.getAssignmentCompatibleType(compatibleType, type, true);
compatibleType = Type.getAssignmentCompatibleType(compatibleType, type, true, enableDecimal256);
if (compatibleType.isInvalid()) {
compatibleType = Type.VARCHAR;
break;
@ -1495,7 +1500,8 @@ public class FunctionCallExpr extends Expr {
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
} else if (fnName.getFunction().equalsIgnoreCase("if")) {
Type[] childTypes = collectChildReturnTypes();
Type assignmentCompatibleType = ScalarType.getAssignmentCompatibleType(childTypes[1], childTypes[2], true);
Type assignmentCompatibleType = ScalarType.getAssignmentCompatibleType(childTypes[1], childTypes[2], true,
enableDecimal256);
if (assignmentCompatibleType.isDecimalV3()) {
if (assignmentCompatibleType.isDecimalV3() && !childTypes[1].equals(assignmentCompatibleType)) {
uncheckedCastChild(assignmentCompatibleType, 1);
@ -1521,7 +1527,8 @@ public class FunctionCallExpr extends Expr {
} else if (fnName.getFunction().equalsIgnoreCase("ifnull")
|| fnName.getFunction().equalsIgnoreCase("nvl")) {
Type[] childTypes = collectChildReturnTypes();
Type assignmentCompatibleType = ScalarType.getAssignmentCompatibleType(childTypes[0], childTypes[1], true);
Type assignmentCompatibleType = ScalarType.getAssignmentCompatibleType(childTypes[0], childTypes[1], true,
enableDecimal256);
if (assignmentCompatibleType != Type.INVALID) {
if (assignmentCompatibleType.isDecimalV3()) {
if (assignmentCompatibleType.isDecimalV3() && !childTypes[0].equals(assignmentCompatibleType)) {
@ -1548,7 +1555,7 @@ public class FunctionCallExpr extends Expr {
Type assignmentCompatibleType = childTypes[0];
for (int i = 1; i < childTypes.length; i++) {
assignmentCompatibleType = ScalarType
.getAssignmentCompatibleType(assignmentCompatibleType, childTypes[i], true);
.getAssignmentCompatibleType(assignmentCompatibleType, childTypes[i], true, enableDecimal256);
}
if (assignmentCompatibleType.isDecimalV3()) {
for (int i = 0; i < childTypes.length; i++) {

View File

@ -143,24 +143,30 @@ public class LargeIntLiteral extends LiteralExpr {
// little endian for hash code
@Override
public ByteBuffer getHashValue(PrimitiveType type) {
ByteBuffer buffer = ByteBuffer.allocate(16);
int buffLen = 0;
if (type == PrimitiveType.DECIMAL256) {
buffLen = 32;
} else {
buffLen = 16;
}
ByteBuffer buffer = ByteBuffer.allocate(buffLen);
buffer.order(ByteOrder.LITTLE_ENDIAN);
byte[] byteArray = value.toByteArray();
int len = byteArray.length;
int end = 0;
if (len > 16) {
end = len - 16;
if (len > buffLen) {
end = len - buffLen;
}
for (int i = len - 1; i >= end; --i) {
buffer.put(byteArray[i]);
}
if (value.signum() >= 0) {
while (len++ < 16) {
while (len++ < buffLen) {
buffer.put((byte) 0);
}
} else {
while (len++ < 16) {
while (len++ < buffLen) {
buffer.put((byte) 0xFF);
}
}

View File

@ -20,6 +20,7 @@ package org.apache.doris.analysis;
import org.apache.doris.catalog.MapType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TTypeDesc;
@ -65,8 +66,9 @@ public class MapLiteral extends LiteralExpr {
if (!MapType.MAP.supportSubType(exprs[idx].getType())) {
throw new AnalysisException("Invalid key type in Map, not support " + exprs[idx].getType());
}
keyType = Type.getAssignmentCompatibleType(keyType, exprs[idx].getType(), true);
valueType = Type.getAssignmentCompatibleType(valueType, exprs[idx + 1].getType(), true);
boolean enableDecimal256 = SessionVariable.getEnableDecimal256();
keyType = Type.getAssignmentCompatibleType(keyType, exprs[idx].getType(), true, enableDecimal256);
valueType = Type.getAssignmentCompatibleType(valueType, exprs[idx + 1].getType(), true, enableDecimal256);
}
if (keyType == Type.INVALID) {

View File

@ -29,7 +29,6 @@ import org.apache.doris.catalog.StructType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TColumnDesc;
import org.apache.doris.thrift.TPrimitiveType;
@ -304,15 +303,7 @@ public class TypeDef implements ParseNode {
break;
}
case DECIMAL256: {
boolean enableNereidsPlanner = false;
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
SessionVariable sessionVariable = connectContext.getSessionVariable();
enableDecimal256 = sessionVariable.enableDecimal256();
enableNereidsPlanner = sessionVariable.isEnableNereidsPlanner();
}
if (enableNereidsPlanner && enableDecimal256) {
if (SessionVariable.getEnableDecimal256()) {
int precision = scalarType.decimalPrecision();
int scale = scalarType.decimalScale();
if (precision < 1 || precision > ScalarType.MAX_DECIMAL256_PRECISION) {

View File

@ -28,6 +28,7 @@ import org.apache.doris.common.io.IOUtils;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.common.util.URI;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TFunction;
import org.apache.doris.thrift.TFunctionBinaryType;
@ -361,14 +362,16 @@ public class Function implements Writable {
return false;
}
for (int i = 0; i < this.argTypes.length; ++i) {
if (!Type.isImplicitlyCastable(other.argTypes[i], this.argTypes[i], true)) {
if (!Type.isImplicitlyCastable(other.argTypes[i], this.argTypes[i], true,
SessionVariable.getEnableDecimal256())) {
return false;
}
}
// Check trailing varargs.
if (this.hasVarArgs) {
for (int i = this.argTypes.length; i < other.argTypes.length; ++i) {
if (!Type.isImplicitlyCastable(other.argTypes[i], getVarArgsType(), true)) {
if (!Type.isImplicitlyCastable(other.argTypes[i], getVarArgsType(), true,
SessionVariable.getEnableDecimal256())) {
return false;
}
}

View File

@ -29,6 +29,7 @@ import org.apache.doris.analysis.MatchPredicate;
import org.apache.doris.builtins.ScalarBuiltins;
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
@ -387,17 +388,19 @@ public class FunctionSet<T> {
}
Type[] args = specializedFunction.getArgs();
Map<String, Type> specializedTypeMap = Maps.newHashMap();
boolean enableDecimal256 = SessionVariable.getEnableDecimal256();
for (int i = 0; i < args.length; i++) {
if (args[i].hasTemplateType()) {
hasTemplateType = true;
args[i] = args[i].specializeTemplateType(requestFunction.getArgs()[i], specializedTypeMap, false);
args[i] = args[i].specializeTemplateType(requestFunction.getArgs()[i], specializedTypeMap, false,
enableDecimal256);
}
}
if (specializedFunction.getReturnType().hasTemplateType()) {
hasTemplateType = true;
specializedFunction.setReturnType(
specializedFunction.getReturnType().specializeTemplateType(
requestFunction.getReturnType(), specializedTypeMap, true));
requestFunction.getReturnType(), specializedTypeMap, true, enableDecimal256));
}
if (LOG.isDebugEnabled()) {
LOG.debug("specializedFunction signature: {}, return type: {}",

View File

@ -29,6 +29,7 @@ import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.datasource.hive.HiveMetaStoreCache;
import org.apache.doris.qe.SessionVariable;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
@ -221,7 +222,9 @@ public class PartitionKey implements Comparable<PartitionKey>, Writable {
if (key1 instanceof MaxLiteral || key2 instanceof MaxLiteral) {
ret = key1.compareLiteral(key2);
} else {
final Type destType = Type.getAssignmentCompatibleType(key1.getType(), key2.getType(), false);
boolean enableDecimal256 = SessionVariable.getEnableDecimal256();
final Type destType = Type.getAssignmentCompatibleType(key1.getType(), key2.getType(), false,
enableDecimal256);
try {
LiteralExpr newKey = key1;
if (key1.getType() != destType) {

View File

@ -56,7 +56,7 @@ public class Multiply extends BinaryArithmetic implements CheckOverflowNullable
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
enableDecimal256 = connectContext.getSessionVariable().isEnableDecimal256();
}
if (enableDecimal256) {
if (retPercision > DecimalV3Type.MAX_DECIMAL256_PRECISION) {

View File

@ -32,7 +32,7 @@ public interface ComputePrecisionForSum extends ComputePrecision {
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
enableDecimal256 = connectContext.getSessionVariable().isEnableDecimal256();
}
return signature.withArgumentType(0, decimalV3Type)
.withReturnType(DecimalV3Type.createDecimalV3Type(

View File

@ -24,6 +24,7 @@ import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.NullType;
import org.apache.doris.nereids.types.coercion.AnyDataType;
import org.apache.doris.nereids.types.coercion.FollowToAnyDataType;
import org.apache.doris.qe.SessionVariable;
import java.util.List;
@ -58,7 +59,8 @@ public interface ImplicitlyCastableSignature extends ComputeSignature {
return false;
}
}
if (Type.isImplicitlyCastable(realType.toCatalogDataType(), signatureType.toCatalogDataType(), true)) {
if (Type.isImplicitlyCastable(realType.toCatalogDataType(), signatureType.toCatalogDataType(), true,
SessionVariable.getEnableDecimal256())) {
return true;
}
} catch (Throwable t) {

View File

@ -92,7 +92,7 @@ public class Avg extends NullableAggregateFunction
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
enableDecimal256 = connectContext.getSessionVariable().isEnableDecimal256();
}
DecimalV3Type decimalV3Type = DecimalV3Type.forType(argumentType);
// DecimalV3 scale lower than DEFAULT_MIN_AVG_DECIMAL128_SCALE should do cast

View File

@ -37,6 +37,7 @@ import org.apache.doris.nereids.types.MapType;
import org.apache.doris.nereids.types.StructField;
import org.apache.doris.nereids.types.StructType;
import org.apache.doris.nereids.util.TypeCoercionUtils;
import org.apache.doris.qe.SessionVariable;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -253,6 +254,7 @@ public abstract class LogicalSetOperation extends AbstractLogicalPlan implements
return DataType.fromCatalogType(Type.getAssignmentCompatibleType(
left.toCatalogDataType(),
right.toCatalogDataType(),
false));
false,
SessionVariable.getEnableDecimal256()));
}
}

View File

@ -110,7 +110,7 @@ public class DecimalV3Type extends FractionalType {
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
enableDecimal256 = connectContext.getSessionVariable().isEnableDecimal256();
}
if (precision > MAX_DECIMAL128_PRECISION && !enableDecimal256) {
throw new NotSupportedException("Datatype DecimalV3 with precision " + precision
@ -133,7 +133,7 @@ public class DecimalV3Type extends FractionalType {
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
enableDecimal256 = connectContext.getSessionVariable().isEnableDecimal256();
}
if (enableDecimal256) {
Preconditions.checkArgument(precision > 0 && precision <= MAX_DECIMAL256_PRECISION,
@ -169,7 +169,7 @@ public class DecimalV3Type extends FractionalType {
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
enableDecimal256 = connectContext.getSessionVariable().isEnableDecimal256();
}
if (range + scale > (enableDecimal256 ? MAX_DECIMAL256_PRECISION : MAX_DECIMAL128_PRECISION)
&& overflowToDouble) {
@ -247,7 +247,7 @@ public class DecimalV3Type extends FractionalType {
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
enableDecimal256 = connectContext.getSessionVariable().isEnableDecimal256();
}
if (enableDecimal256) {
return 32;

View File

@ -2840,7 +2840,16 @@ public class SessionVariable implements Serializable, Writable {
return connectContext.getSessionVariable().enableAggState;
}
public boolean enableDecimal256() {
public static boolean getEnableDecimal256() {
ConnectContext connectContext = ConnectContext.get();
if (connectContext == null) {
return false;
}
SessionVariable sessionVariable = connectContext.getSessionVariable();
return sessionVariable.isEnableNereidsPlanner() && sessionVariable.isEnableDecimal256();
}
public boolean isEnableDecimal256() {
return enableDecimal256;
}

View File

@ -228,6 +228,7 @@ public class StatisticsUtil {
case DECIMAL32:
case DECIMAL64:
case DECIMAL128:
case DECIMAL256:
DecimalLiteral decimalLiteral = new DecimalLiteral(columnValue);
decimalLiteral.checkPrecisionAndScale(scalarType.getScalarPrecision(), scalarType.getScalarScale());
return decimalLiteral;
@ -273,6 +274,7 @@ public class StatisticsUtil {
case DECIMAL32:
case DECIMAL64:
case DECIMAL128:
case DECIMAL256:
return Double.parseDouble(columnValue);
case DATE:
case DATEV2: