diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/validate/TypeChecker.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/validate/TypeChecker.java index 7970afb87df98..985e1d83eb9e4 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/validate/TypeChecker.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/validate/TypeChecker.java @@ -14,6 +14,8 @@ package com.starrocks.sql.optimizer.validate; +import com.starrocks.catalog.PrimitiveType; +import com.starrocks.catalog.ScalarType; import com.starrocks.catalog.Type; import com.starrocks.sql.analyzer.SemanticException; import com.starrocks.sql.optimizer.OptExpression; @@ -190,7 +192,25 @@ private void checkAggCall(Map aggregations, Agg } } + private boolean checkDecimalType(Type decimalType) { + ScalarType type = (ScalarType) decimalType; + final int scale = type.getScalarScale(); + final int precision = type.getScalarPrecision(); + final PrimitiveType primitiveType = type.getPrimitiveType(); + return scale >= 0 && scale <= precision && precision <= PrimitiveType.getMaxPrecisionOfDecimal(primitiveType); + } + private void checkColType(ScalarOperator arg, ScalarOperator expr, Type defined, Type actual) { + if (actual.isDecimalV3()) { + checkArgument(checkDecimalType(actual), + "expr '%s' invalid actual type: %s", + PREFIX, expr, actual); + } + if (defined.isDecimalV3()) { + checkArgument(checkDecimalType(actual), + "expr '%s' invalid defined type: %s", + PREFIX, expr, defined); + } checkArgument(actual.matchesType(defined), "%s the type of arg %s in expr '%s' is defined as %s, but the actual type is %s", PREFIX, arg, expr, defined, actual);