Skip to content

Commit

Permalink
[fix](fe-ut) fix npe of fe ut
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktengg committed Oct 25, 2023
1 parent 0eea194 commit 8b978fc
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
11 changes: 8 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/TypeDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,14 @@ private void analyzeScalarType(ScalarType scalarType)
break;
}
case DECIMAL256: {
SessionVariable sessionVariable = ConnectContext.get().getSessionVariable();
boolean enableDecimal256 = sessionVariable.enableDecimal256();
boolean enableNereidsPlanner = sessionVariable.isEnableNereidsPlanner();
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) {
int precision = scalarType.decimalPrecision();
int scale = scalarType.decimalScale();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1, DecimalV3Type t2)
int retPercision = t1.getPrecision() + t2.getPrecision();
int retScale = t1.getScale() + t2.getScale();
if (retPercision > DecimalV3Type.MAX_DECIMAL128_PRECISION) {
boolean enableDecimal256 = ConnectContext.get().getSessionVariable().enableDecimal256();
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
}
if (enableDecimal256) {
if (retPercision > DecimalV3Type.MAX_DECIMAL256_PRECISION) {
retPercision = DecimalV3Type.MAX_DECIMAL256_PRECISION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ default FunctionSignature computePrecision(FunctionSignature signature) {
DataType argumentType = getArgumentType(0);
if (signature.getArgType(0) instanceof DecimalV3Type) {
DecimalV3Type decimalV3Type = DecimalV3Type.forType(argumentType);
boolean enableDecimal256 = ConnectContext.get().getSessionVariable().enableDecimal256();
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
}
return signature.withArgumentType(0, decimalV3Type)
.withReturnType(DecimalV3Type.createDecimalV3Type(
enableDecimal256 ? DecimalV3Type.MAX_DECIMAL256_PRECISION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ public void checkLegalityBeforeTypeCoercion() {
public FunctionSignature computePrecision(FunctionSignature signature) {
DataType argumentType = getArgumentType(0);
if (signature.getArgType(0) instanceof DecimalV3Type) {
boolean enableDecimal256 = ConnectContext.get().getSessionVariable().enableDecimal256();
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
}
DecimalV3Type decimalV3Type = DecimalV3Type.forType(argumentType);
// DecimalV3 scale lower than DEFAULT_MIN_AVG_DECIMAL128_SCALE should do cast
int precision = decimalV3Type.getPrecision();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ public static DecimalV3Type createDecimalV3Type(int precision, int scale) {
Preconditions.checkArgument(scale >= 0, "scale should not smaller than 0, but real scale is " + scale);
Preconditions.checkArgument(precision >= scale, "precision should not smaller than scale,"
+ " but precision is " + precision, ", scale is " + scale);
boolean enableDecimal256 = ConnectContext.get().getSessionVariable().enableDecimal256();
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
}
if (precision > MAX_DECIMAL128_PRECISION && !enableDecimal256) {
throw new NotSupportedException("Datatype DecimalV3 with precision " + precision
+ ", which is greater than 38 is disabled by default. set enable_decimal256 = true to enable it.");
Expand All @@ -126,7 +130,11 @@ public static DecimalV3Type createDecimalV3Type(BigDecimal bigDecimal) {
* create DecimalV3Type, not throwing NotSupportedException.
*/
public static DecimalV3Type createDecimalV3TypeLooseCheck(int precision, int scale) {
boolean enableDecimal256 = ConnectContext.get().getSessionVariable().enableDecimal256();
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
}
if (enableDecimal256) {
Preconditions.checkArgument(precision > 0 && precision <= MAX_DECIMAL256_PRECISION,
"precision should in (0, " + MAX_DECIMAL256_PRECISION + "], but real precision is " + precision);
Expand Down Expand Up @@ -158,7 +166,11 @@ private static DataType widerDecimalV3Type(
boolean overflowToDouble) {
int scale = Math.max(leftScale, rightScale);
int range = Math.max(leftPrecision - leftScale, rightPrecision - rightScale);
boolean enableDecimal256 = ConnectContext.get().getSessionVariable().enableDecimal256();
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
}
if (range + scale > (enableDecimal256 ? MAX_DECIMAL256_PRECISION : MAX_DECIMAL128_PRECISION)
&& overflowToDouble) {
return DoubleType.INSTANCE;
Expand Down Expand Up @@ -232,7 +244,11 @@ public int width() {
} else if (precision <= MAX_DECIMAL128_PRECISION) {
return 16;
} else {
boolean enableDecimal256 = ConnectContext.get().getSessionVariable().enableDecimal256();
boolean enableDecimal256 = false;
ConnectContext connectContext = ConnectContext.get();
if (connectContext != null) {
enableDecimal256 = connectContext.getSessionVariable().enableDecimal256();
}
if (enableDecimal256) {
return 32;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void testTimeV2() throws AnalysisException {
public void testDecimalPreFail() throws AnalysisException {
TypeDef type;
if (Config.enable_decimal_conversion) {
type = TypeDef.createDecimal(39, 3);
type = TypeDef.createDecimal(77, 3);
} else {
type = TypeDef.createDecimal(28, 3);
}
Expand Down

0 comments on commit 8b978fc

Please sign in to comment.