Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] add Type Check for decimal input (backport #53217) #53256

Open
wants to merge 1 commit into
base: branch-3.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -195,7 +197,25 @@ private void checkAggCall(Map<ColumnRefOperator, CallOperator> 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);
Expand Down
Loading