From cae064822c7cbaae035ffd4ccf2b8843d7ee01ab Mon Sep 17 00:00:00 2001 From: Joanna Hulboj Date: Sat, 18 Feb 2023 17:20:57 +0000 Subject: [PATCH] FIXUP: FunctionArrayMapped - Simpler arg passing for check/exec --- src/Functions/array/FunctionArrayMapped.h | 12 +++++------- src/Functions/array/arraySort.cpp | 24 +++++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Functions/array/FunctionArrayMapped.h b/src/Functions/array/FunctionArrayMapped.h index 42b7ae69a40..3c5cd29fff5 100644 --- a/src/Functions/array/FunctionArrayMapped.h +++ b/src/Functions/array/FunctionArrayMapped.h @@ -194,8 +194,7 @@ public: arguments[num_fixed_params].type->getName()); if constexpr (num_fixed_params) - Impl::checkArguments( - std::span(std::begin(arguments), num_fixed_params), getName()); + Impl::checkArguments(getName(), arguments.data()); DataTypePtr nested_type = data_type->getNestedType(); @@ -229,8 +228,7 @@ public: arguments[0].type->getName()); if constexpr (num_fixed_params) - Impl::checkArguments( - std::span(std::begin(arguments) + 1, num_fixed_params), getName()); + Impl::checkArguments(getName(), arguments.data() + 1); /// The types of the remaining arguments are already checked in getLambdaArgumentTypes. @@ -294,7 +292,7 @@ public: return Impl::execute( *column_array, column_array->getNestedColumn().getDataPtr(), - std::span(std::begin(arguments), num_fixed_params)); + arguments.data()); else return Impl::execute(*column_array, column_array->getNestedColumn().getDataPtr()); } @@ -304,7 +302,7 @@ public: return Impl::execute( *column_array, column_array->getDataPtr(), - std::span(std::begin(arguments), num_fixed_params)); + arguments.data()); else return Impl::execute(*column_array, column_array->getDataPtr()); } @@ -439,7 +437,7 @@ public: return Impl::execute( *column_first_array, lambda_result.column, - std::span(std::begin(arguments) + 1, num_fixed_params)); + arguments.data() + 1); else return Impl::execute(*column_first_array, lambda_result.column); } diff --git a/src/Functions/array/arraySort.cpp b/src/Functions/array/arraySort.cpp index ebdc408dbbd..0188324bc19 100644 --- a/src/Functions/array/arraySort.cpp +++ b/src/Functions/array/arraySort.cpp @@ -9,6 +9,7 @@ namespace DB namespace ErrorCodes { extern const int ILLEGAL_TYPE_OF_ARGUMENT; + extern const int LOGICAL_ERROR; } /** Sort arrays, by values of its elements, or by values of corresponding elements of calculated expression (known as "schwartzsort"). @@ -45,31 +46,38 @@ struct ArraySortImpl } }; - static void checkArguments(std::span arguments, const String & name) + static void checkArguments(const String & name, const ColumnWithTypeAndName * fixed_arguments) requires(num_fixed_params) { - if (arguments.size() != 1) - throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} needs limit argument", name); - - WhichDataType which(arguments[0].type.get()); + if (!fixed_arguments) + throw Exception( + ErrorCodes::LOGICAL_ERROR, + "Expected fixed arguments to get the limit for partial array sort" + ); + WhichDataType which(fixed_arguments[0].type.get()); if (!which.isUInt() && !which.isInt()) throw Exception( ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of limit argument of function {} (must be UInt or Int)", - arguments[0].type->getName(), + fixed_arguments[0].type->getName(), name); } static ColumnPtr execute( const ColumnArray & array, ColumnPtr mapped, - std::span arguments [[maybe_unused]] = {}) + const ColumnWithTypeAndName * fixed_arguments [[maybe_unused]] = nullptr) { [[maybe_unused]] const auto limit = [&]() -> size_t { if constexpr (is_partial) { - return arguments[0].column.get()->getUInt(0); + if (!fixed_arguments) + throw Exception( + ErrorCodes::LOGICAL_ERROR, + "Expected fixed arguments to get the limit for partial array sort" + ); + return fixed_arguments[0].column.get()->getUInt(0); } return 0; }();