diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 6cc8e6da7c..3632c3577a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -101,7 +101,8 @@ public class FunctionCallExpr extends Expr { java.util.function.BiFunction, Type, Type> roundRule = (children, returnType) -> { Preconditions.checkArgument(children != null && children.size() > 0); if (children.size() == 1 && children.get(0).getType().isDecimalV3()) { - return ScalarType.createDecimalV3Type(children.get(0).getType().getPrecision(), 0); + return ScalarType.createDecimalV3Type(children.get(0).getType().getPrecision(), + ((ScalarType) children.get(0).getType()).decimalScale()); } else if (children.size() == 2) { Preconditions.checkArgument(children.get(1) instanceof IntLiteral || (children.get(1) instanceof CastExpr diff --git a/regression-test/data/query_p0/sql_functions/math_functions/test_round.out b/regression-test/data/query_p0/sql_functions/math_functions/test_round.out index aff17c5dd0..3f2ff0ab96 100644 --- a/regression-test/data/query_p0/sql_functions/math_functions/test_round.out +++ b/regression-test/data/query_p0/sql_functions/math_functions/test_round.out @@ -11,6 +11,18 @@ -- !select -- 10.12 +-- !select -- +16.000 16.00000 16.00000 + +-- !select -- +16.000 16.00000 16.00000 + +-- !select -- +17.000 17.00000 17.00000 + +-- !select -- +16.000 16.00000 16.00000 + -- !select -- 16.030 16.03000 16.03000 diff --git a/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy b/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy index e0b63b300f..d56cd0fac4 100644 --- a/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy +++ b/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy @@ -31,6 +31,10 @@ suite("test_round") { PROPERTIES ( "replication_num" = "1" ); """ sql """ insert into `${tableName}` values(16.025, 16.025, 16.025); """ + qt_select """ SELECT round(col1), round(col2), round(col3) FROM `${tableName}`; """ + qt_select """ SELECT floor(col1), floor(col2), floor(col3) FROM `${tableName}`; """ + qt_select """ SELECT ceil(col1), ceil(col2), ceil(col3) FROM `${tableName}`; """ + qt_select """ SELECT round_bankers(col1), round_bankers(col2), round_bankers(col3) FROM `${tableName}`; """ qt_select """ SELECT round(col1, 2), round(col2, 2), round(col3, 2) FROM `${tableName}`; """ qt_select """ SELECT floor(col1, 2), floor(col2, 2), floor(col3, 2) FROM `${tableName}`; """ qt_select """ SELECT ceil(col1, 2), ceil(col2, 2), ceil(col3, 2) FROM `${tableName}`; """