[function](round) fix decimal scale for scale not specified (#15541)
This commit is contained in:
@ -101,7 +101,8 @@ public class FunctionCallExpr extends Expr {
|
||||
java.util.function.BiFunction<ArrayList<Expr>, 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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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}`; """
|
||||
|
||||
Reference in New Issue
Block a user