diff --git a/dbms/src/DataTypes/FieldToDataType.cpp b/dbms/src/DataTypes/FieldToDataType.cpp index 3086c9167c2..18fa0e97b88 100644 --- a/dbms/src/DataTypes/FieldToDataType.cpp +++ b/dbms/src/DataTypes/FieldToDataType.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include diff --git a/dbms/src/Functions/FunctionsRound.h b/dbms/src/Functions/FunctionsRound.h index 92d70633c12..3c9be5f15b9 100644 --- a/dbms/src/Functions/FunctionsRound.h +++ b/dbms/src/Functions/FunctionsRound.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -608,33 +607,28 @@ public: void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t) override { - const ColumnConst * array = checkAndGetColumnConst(block.getByPosition(arguments[1]).column.get()); - if (!array) - { - throw Exception{"Second argument of function " + getName() + " must be constant array.", ErrorCodes::ILLEGAL_COLUMN}; - } - auto in_column = block.getByPosition(arguments[0]).column; const auto & in_type = block.getByPosition(arguments[0]).type; + auto array_column = block.getByPosition(arguments[1]).column; + const auto & array_type = block.getByPosition(arguments[1]).type; + const auto & return_type = block.getByPosition(result).type; auto column_result = return_type->createColumn(); auto out = column_result.get(); if (!in_type->equals(*return_type)) - { in_column = castColumn(block.getByPosition(arguments[0]), return_type, context); - } + + if (!array_type->equals(*return_type)) + array_column = castColumn(block.getByPosition(arguments[1]), std::make_shared(return_type), context); const auto in = in_column.get(); - auto boundaries = array->getValue(); + auto boundaries = typeid_cast(*array_column).getValue(); size_t num_boundaries = boundaries.size(); if (!num_boundaries) throw Exception("Empty array is illegal for boundaries in " + getName() + " function", ErrorCodes::BAD_ARGUMENTS); - for (size_t i = 0; i < num_boundaries; ++i) - boundaries[i] = convertFieldToType(boundaries[i], *return_type); - if (!executeNum(in, out, boundaries) && !executeNum(in, out, boundaries) && !executeNum(in, out, boundaries) diff --git a/dbms/tests/queries/0_stateless/00805_round_down.reference b/dbms/tests/queries/0_stateless/00805_round_down.reference index b37e8c8f1a0..0ed04c7757f 100644 --- a/dbms/tests/queries/0_stateless/00805_round_down.reference +++ b/dbms/tests/queries/0_stateless/00805_round_down.reference @@ -61,3 +61,23 @@ 0.07000 4.00000 0.08000 4.00000 0.09000 4.00000 +0.00000 0.04000 +0.01000 0.04000 +0.02000 0.04000 +0.03000 0.04000 +0.04000 0.04000 +0.05000 0.05000 +0.06000 0.06000 +0.07000 0.06000 +0.08000 0.06000 +0.09000 0.06000 +0.00000 0.04000 +0.01000 0.04000 +0.02000 0.04000 +0.03000 0.04000 +0.04000 0.04000 +0.05000 0.05000 +0.06000 0.06000 +0.07000 0.06000 +0.08000 0.06000 +0.09000 0.06000 diff --git a/dbms/tests/queries/0_stateless/00805_round_down.sql b/dbms/tests/queries/0_stateless/00805_round_down.sql index 0ba4804031c..bf25f7be952 100644 --- a/dbms/tests/queries/0_stateless/00805_round_down.sql +++ b/dbms/tests/queries/0_stateless/00805_round_down.sql @@ -7,6 +7,7 @@ SELECT 1 as x, roundDown(x, [6, 5, 4]); SET send_logs_level = 'none'; SELECT 1 as x, roundDown(x, []); -- { serverError 43 } SELECT 1 as x, roundDown(x, emptyArrayUInt8()); -- { serverError 44 } +SELECT roundDown(number, [number]) FROM system.numbers LIMIT 10; -- { serverError 44 } SELECT 1 as x, roundDown(x, [1]); SELECT 1 as x, roundDown(x, [1.5]); @@ -14,4 +15,5 @@ SELECT 1 as x, roundDown(x, [1.5]); SELECT number % 10 as x, roundDown(x, (SELECT groupArray(number * 1.25) FROM numbers(100000))) FROM system.numbers LIMIT 10; SELECT toDecimal64(number, 5) / 100 as x, roundDown(x, [4, 5, 6]) FROM system.numbers LIMIT 10; - +SELECT toDecimal64(number, 5) / 100 as x, roundDown(x, [toDecimal64(0.04, 5), toDecimal64(0.05, 5), toDecimal64(0.06, 5)]) FROM system.numbers LIMIT 10; +SELECT toDecimal64(number, 5) / 100 as x, roundDown(x, [toDecimal32(0.04, 2), toDecimal32(0.05, 2), toDecimal32(0.06, 2)]) FROM system.numbers LIMIT 10;