diff --git a/src/Functions/FunctionStringReplace.h b/src/Functions/FunctionStringReplace.h index 137c2241b7f..4ec85591726 100644 --- a/src/Functions/FunctionStringReplace.h +++ b/src/Functions/FunctionStringReplace.h @@ -52,17 +52,17 @@ public: return std::make_shared(); } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const override { - const ColumnPtr column_src = columns[arguments[0]].column; - const ColumnPtr column_needle = columns[arguments[1]].column; - const ColumnPtr column_replacement = columns[arguments[2]].column; + const ColumnPtr column_src = arguments[0].column; + const ColumnPtr column_needle = arguments[1].column; + const ColumnPtr column_replacement = arguments[2].column; if (!isColumnConst(*column_needle) || !isColumnConst(*column_replacement)) throw Exception("2nd and 3rd arguments of function " + getName() + " must be constants.", ErrorCodes::ILLEGAL_COLUMN); - const IColumn * c1 = columns[arguments[1]].column.get(); - const IColumn * c2 = columns[arguments[2]].column.get(); + const IColumn * c1 = arguments[1].column.get(); + const IColumn * c2 = arguments[2].column.get(); const ColumnConst * c1_const = typeid_cast(c1); const ColumnConst * c2_const = typeid_cast(c2); String needle = c1_const->getValue(); @@ -75,17 +75,17 @@ public: { auto col_res = ColumnString::create(); Impl::vector(col->getChars(), col->getOffsets(), needle, replacement, col_res->getChars(), col_res->getOffsets()); - columns[result].column = std::move(col_res); + return col_res; } else if (const ColumnFixedString * col_fixed = checkAndGetColumn(column_src.get())) { auto col_res = ColumnString::create(); Impl::vectorFixed(col_fixed->getChars(), col_fixed->getN(), needle, replacement, col_res->getChars(), col_res->getOffsets()); - columns[result].column = std::move(col_res); + return col_res; } else throw Exception( - "Illegal column " + columns[arguments[0]].column->getName() + " of first argument of function " + getName(), + "Illegal column " + arguments[0].column->getName() + " of first argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN); } }; diff --git a/src/Functions/FunctionStringToString.h b/src/Functions/FunctionStringToString.h index 56f434a2ffa..ebca5882d64 100644 --- a/src/Functions/FunctionStringToString.h +++ b/src/Functions/FunctionStringToString.h @@ -52,20 +52,20 @@ public: bool useDefaultImplementationForConstants() const override { return true; } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const override { - const ColumnPtr column = columns[arguments[0]].column; + const ColumnPtr column = arguments[0].column; if (const ColumnString * col = checkAndGetColumn(column.get())) { auto col_res = ColumnString::create(); Impl::vector(col->getChars(), col->getOffsets(), col_res->getChars(), col_res->getOffsets()); - columns[result].column = std::move(col_res); + return col_res; } else if (const ColumnFixedString * col_fixed = checkAndGetColumn(column.get())) { auto col_res = ColumnFixedString::create(col_fixed->getN()); Impl::vectorFixed(col_fixed->getChars(), col_fixed->getN(), col_res->getChars()); - columns[result].column = std::move(col_res); + return col_res; } else throw Exception( diff --git a/src/Functions/FunctionsExternalModels.cpp b/src/Functions/FunctionsExternalModels.cpp index 14ced517e6a..9c1892012e1 100644 --- a/src/Functions/FunctionsExternalModels.cpp +++ b/src/Functions/FunctionsExternalModels.cpp @@ -69,9 +69,9 @@ DataTypePtr FunctionModelEvaluate::getReturnTypeImpl(const ColumnsWithTypeAndNam return type; } -void FunctionModelEvaluate::executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) const +ColumnPtr FunctionModelEvaluate::executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const { - const auto * name_col = checkAndGetColumnConst(columns[arguments[0]].column.get()); + const auto * name_col = checkAndGetColumnConst(arguments[0].column.get()); if (!name_col) throw Exception("First argument of function " + getName() + " must be a constant string", ErrorCodes::ILLEGAL_COLUMN); @@ -85,7 +85,7 @@ void FunctionModelEvaluate::executeImpl(ColumnsWithTypeAndName & columns, const column_ptrs.reserve(arguments.size()); for (auto arg : ext::range(1, arguments.size())) { - auto & column = columns[arguments[arg]].column; + auto & column = arguments[arg].column; column_ptrs.push_back(column.get()); if (auto full_column = column->convertToFullColumnIfConst()) { @@ -130,7 +130,7 @@ void FunctionModelEvaluate::executeImpl(ColumnsWithTypeAndName & columns, const res = ColumnNullable::create(res, null_map); } - columns[result].column = res; + return res; } void registerFunctionsExternalModels(FunctionFactory & factory) diff --git a/src/Functions/FunctionsExternalModels.h b/src/Functions/FunctionsExternalModels.h index 40dad72bfc4..336dc164248 100644 --- a/src/Functions/FunctionsExternalModels.h +++ b/src/Functions/FunctionsExternalModels.h @@ -32,7 +32,7 @@ public: DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override; - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) const override; + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override; private: const ExternalModelsLoader & models_loader; diff --git a/src/Functions/FunctionsHashing.h b/src/Functions/FunctionsHashing.h index 3bed85e30bc..678214cdbad 100644 --- a/src/Functions/FunctionsHashing.h +++ b/src/Functions/FunctionsHashing.h @@ -543,9 +543,9 @@ public: bool useDefaultImplementationForConstants() const override { return true; } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const override { - if (const ColumnString * col_from = checkAndGetColumn(columns[arguments[0]].column.get())) + if (const ColumnString * col_from = checkAndGetColumn(arguments[0].column.get())) { auto col_to = ColumnFixedString::create(Impl::length); @@ -566,10 +566,10 @@ public: current_offset = offsets[i]; } - columns[result].column = std::move(col_to); + return col_to; } else if ( - const ColumnFixedString * col_from_fix = checkAndGetColumn(columns[arguments[0]].column.get())) + const ColumnFixedString * col_from_fix = checkAndGetColumn(arguments[0].column.get())) { auto col_to = ColumnFixedString::create(Impl::length); const typename ColumnFixedString::Chars & data = col_from_fix->getChars(); @@ -582,10 +582,10 @@ public: Impl::apply( reinterpret_cast(&data[i * length]), length, reinterpret_cast(&chars_to[i * Impl::length])); } - columns[result].column = std::move(col_to); + return col_to; } else - throw Exception("Illegal column " + columns[arguments[0]].column->getName() + throw Exception("Illegal column " + arguments[0].column->getName() + " of first argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN); } @@ -604,11 +604,11 @@ private: using ToType = typename Impl::ReturnType; template - void executeType(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result) const + ColumnPtr executeType(ColumnsWithTypeAndName & arguments) const { using ColVecType = std::conditional_t, ColumnDecimal, ColumnVector>; - if (const ColVecType * col_from = checkAndGetColumn(columns[arguments[0]].column.get())) + if (const ColVecType * col_from = checkAndGetColumn(arguments[0].column.get())) { auto col_to = ColumnVector::create(); @@ -620,10 +620,10 @@ private: for (size_t i = 0; i < size; ++i) vec_to[i] = Impl::apply(vec_from[i]); - columns[result].column = std::move(col_to); + return col_to; } else - throw Exception("Illegal column " + columns[arguments[0]].column->getName() + throw Exception("Illegal column " + arguments[0].column->getName() + " of first argument of function " + Name::name, ErrorCodes::ILLEGAL_COLUMN); } @@ -647,25 +647,37 @@ public: bool useDefaultImplementationForConstants() const override { return true; } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const override { - const IDataType * from_type = columns[arguments[0]].type.get(); + const IDataType * from_type = arguments[0].type.get(); WhichDataType which(from_type); - if (which.isUInt8()) executeType(columns, arguments, result); - else if (which.isUInt16()) executeType(columns, arguments, result); - else if (which.isUInt32()) executeType(columns, arguments, result); - else if (which.isUInt64()) executeType(columns, arguments, result); - else if (which.isInt8()) executeType(columns, arguments, result); - else if (which.isInt16()) executeType(columns, arguments, result); - else if (which.isInt32()) executeType(columns, arguments, result); - else if (which.isInt64()) executeType(columns, arguments, result); - else if (which.isDate()) executeType(columns, arguments, result); - else if (which.isDateTime()) executeType(columns, arguments, result); - else if (which.isDecimal32()) executeType(columns, arguments, result); - else if (which.isDecimal64()) executeType(columns, arguments, result); + if (which.isUInt8()) + return executeType(arguments); + else if (which.isUInt16()) + return executeType(arguments); + else if (which.isUInt32()) + return executeType(arguments); + else if (which.isUInt64()) + return executeType(arguments); + else if (which.isInt8()) + return executeType(arguments); + else if (which.isInt16()) + return executeType(arguments); + else if (which.isInt32()) + return executeType(arguments); + else if (which.isInt64()) + return executeType(arguments); + else if (which.isDate()) + return executeType(arguments); + else if (which.isDateTime()) + return executeType(arguments); + else if (which.isDecimal32()) + return executeType(arguments); + else if (which.isDecimal64()) + return executeType(arguments); else - throw Exception("Illegal type " + columns[arguments[0]].type->getName() + " of argument of function " + getName(), + throw Exception("Illegal type " + arguments[0].type->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); } }; @@ -689,9 +701,9 @@ public: #endif } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override { - selector.selectAndExecute(columns, arguments, result, input_rows_count); + return selector.selectAndExecute(arguments, result_type, input_rows_count); } static FunctionPtr create(const Context & context) @@ -886,7 +898,7 @@ private: } else if (const ColumnConst * col_from_const = checkAndGetColumnConstStringOrFixedString(column)) { - String value = col_from_const->getValue().data(); + String value = col_from_const->getValue(); const ToType hash = Impl::apply(value.data(), value.size()); const size_t size = vec_to.size(); @@ -1041,7 +1053,7 @@ public: return std::make_shared>(); } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override { size_t rows = input_rows_count; auto col_to = ColumnVector::create(rows); @@ -1057,13 +1069,10 @@ public: /// The function supports arbitrary number of arguments of arbitrary types. bool is_first_argument = true; - for (size_t i = 0; i < arguments.size(); ++i) - { - const ColumnWithTypeAndName & col = columns[arguments[i]]; + for (const auto & col : arguments) executeForArgument(col.type.get(), col.column.get(), vec_to, is_first_argument); - } - columns[result].column = std::move(col_to); + return col_to; } }; @@ -1086,9 +1095,9 @@ public: #endif } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override { - selector.selectAndExecute(columns, arguments, result, input_rows_count); + return selector.selectAndExecute(arguments, result_type, input_rows_count); } static FunctionPtr create(const Context & context) @@ -1118,7 +1127,7 @@ struct URLHierarchyHashImpl { static size_t findLevelLength(const UInt64 level, const char * begin, const char * end) { - auto pos = begin; + const auto * pos = begin; /// Let's parse everything that goes before the path @@ -1192,7 +1201,7 @@ public: throw Exception{"Number of arguments for function " + getName() + " doesn't match: passed " + toString(arg_count) + ", should be 1 or 2.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH}; - const auto first_arg = arguments.front().get(); + const auto * first_arg = arguments.front().get(); if (!WhichDataType(first_arg).isString()) throw Exception{"Illegal type " + first_arg->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT}; @@ -1209,24 +1218,24 @@ public: bool useDefaultImplementationForConstants() const override { return true; } ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1}; } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const override { const auto arg_count = arguments.size(); if (arg_count == 1) - executeSingleArg(columns, arguments, result); + return executeSingleArg(arguments); else if (arg_count == 2) - executeTwoArgs(columns, arguments, result); + return executeTwoArgs(arguments); else throw Exception{"got into IFunction::execute with unexpected number of arguments", ErrorCodes::LOGICAL_ERROR}; } private: - void executeSingleArg(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, const size_t result) const + ColumnPtr executeSingleArg(ColumnsWithTypeAndName & arguments) const { - const auto col_untyped = columns[arguments.front()].column.get(); + const auto * col_untyped = arguments.front().column.get(); - if (const auto col_from = checkAndGetColumn(col_untyped)) + if (const auto * col_from = checkAndGetColumn(col_untyped)) { const auto size = col_from->size(); auto col_to = ColumnUInt64::create(size); @@ -1245,23 +1254,23 @@ private: current_offset = offsets[i]; } - columns[result].column = std::move(col_to); + return col_to; } else - throw Exception{"Illegal column " + columns[arguments[0]].column->getName() + + throw Exception{"Illegal column " + arguments[0].column->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN}; } - void executeTwoArgs(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, const size_t result) const + ColumnPtr executeTwoArgs(ColumnsWithTypeAndName & arguments) const { - const auto level_col = columns[arguments.back()].column.get(); + const auto * level_col = arguments.back().column.get(); if (!isColumnConst(*level_col)) throw Exception{"Second argument of function " + getName() + " must be an integral constant", ErrorCodes::ILLEGAL_COLUMN}; const auto level = level_col->get64(0); - const auto col_untyped = columns[arguments.front()].column.get(); - if (const auto col_from = checkAndGetColumn(col_untyped)) + const auto * col_untyped = arguments.front().column.get(); + if (const auto * col_from = checkAndGetColumn(col_untyped)) { const auto size = col_from->size(); auto col_to = ColumnUInt64::create(size); @@ -1281,10 +1290,10 @@ private: current_offset = offsets[i]; } - columns[result].column = std::move(col_to); + return col_to; } else - throw Exception{"Illegal column " + columns[arguments[0]].column->getName() + + throw Exception{"Illegal column " + arguments[0].column->getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN}; } }; diff --git a/src/Functions/FunctionsJSON.cpp b/src/Functions/FunctionsJSON.cpp index 6f83bc401de..7478c1627af 100644 --- a/src/Functions/FunctionsJSON.cpp +++ b/src/Functions/FunctionsJSON.cpp @@ -10,13 +10,13 @@ namespace ErrorCodes } -std::vector FunctionJSONHelpers::prepareMoves(const char * function_name, ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t first_index_argument, size_t num_index_arguments) +std::vector FunctionJSONHelpers::prepareMoves(const char * function_name, ColumnsWithTypeAndName & columns, size_t first_index_argument, size_t num_index_arguments) { std::vector moves; moves.reserve(num_index_arguments); for (const auto i : ext::range(first_index_argument, first_index_argument + num_index_arguments)) { - const auto & column = columns[arguments[i]]; + const auto & column = columns[i]; if (!isString(column.type) && !isInteger(column.type)) throw Exception{"The argument " + std::to_string(i + 1) + " of function " + String(function_name) + " should be a string specifying key or an integer specifying index, illegal type: " + column.type->getName(), diff --git a/src/Functions/FunctionsJSON.h b/src/Functions/FunctionsJSON.h index e55288a2367..0fcf1f57f82 100644 --- a/src/Functions/FunctionsJSON.h +++ b/src/Functions/FunctionsJSON.h @@ -55,22 +55,22 @@ public: class Executor { public: - static void run(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result_pos, size_t input_rows_count) + static ColumnPtr run(ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) { - MutableColumnPtr to{columns[result_pos].type->createColumn()}; + MutableColumnPtr to{result_type->createColumn()}; to->reserve(input_rows_count); - if (arguments.size() < 1) + if (arguments.empty()) throw Exception{"Function " + String(Name::name) + " requires at least one argument", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH}; - const auto & first_column = columns[arguments[0]]; + const auto & first_column = arguments[0]; if (!isString(first_column.type)) throw Exception{"The first argument of function " + String(Name::name) + " should be a string containing JSON, illegal type: " + first_column.type->getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT}; const ColumnPtr & arg_json = first_column.column; - auto col_json_const = typeid_cast(arg_json.get()); - auto col_json_string + const auto * col_json_const = typeid_cast(arg_json.get()); + const auto * col_json_string = typeid_cast(col_json_const ? col_json_const->getDataColumnPtr().get() : arg_json.get()); if (!col_json_string) @@ -79,8 +79,8 @@ public: const ColumnString::Chars & chars = col_json_string->getChars(); const ColumnString::Offsets & offsets = col_json_string->getOffsets(); - size_t num_index_arguments = Impl::getNumberOfIndexArguments(columns, arguments); - std::vector moves = prepareMoves(Name::name, columns, arguments, 1, num_index_arguments); + size_t num_index_arguments = Impl::getNumberOfIndexArguments(arguments); + std::vector moves = prepareMoves(Name::name, arguments, 1, num_index_arguments); /// Preallocate memory in parser if necessary. JSONParser parser; @@ -94,8 +94,8 @@ public: Impl impl; /// prepare() does Impl-specific preparation before handling each row. - if constexpr (has_member_function_prepare::*)(const char *, const ColumnsWithTypeAndName &, const ColumnNumbers &, size_t)>::value) - impl.prepare(Name::name, columns, arguments, result_pos); + if constexpr (has_member_function_prepare::*)(const char *, const ColumnsWithTypeAndName &, const DataTypePtr &)>::value) + impl.prepare(Name::name, arguments, result_type); using Element = typename JSONParser::Element; @@ -121,7 +121,7 @@ public: /// Perform moves. Element element; std::string_view last_key; - bool moves_ok = performMoves(columns, arguments, i, document, moves, element, last_key); + bool moves_ok = performMoves(arguments, i, document, moves, element, last_key); if (moves_ok) added_to_column = impl.insertResultToColumn(*to, element, last_key); @@ -131,7 +131,7 @@ public: if (!added_to_column) to->insertDefault(); } - columns[result_pos].column = std::move(to); + return to; } }; @@ -166,11 +166,11 @@ private: String key; }; - static std::vector prepareMoves(const char * function_name, ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t first_index_argument, size_t num_index_arguments); + static std::vector prepareMoves(const char * function_name, ColumnsWithTypeAndName & columns, size_t first_index_argument, size_t num_index_arguments); /// Performs moves of types MoveType::Index and MoveType::ConstIndex. template - static bool performMoves(const ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t row, + static bool performMoves(const ColumnsWithTypeAndName & arguments, size_t row, const typename JSONParser::Element & document, const std::vector & moves, typename JSONParser::Element & element, std::string_view & last_key) { @@ -196,14 +196,14 @@ private: } case MoveType::Index: { - Int64 index = (*columns[arguments[j + 1]].column)[row].get(); + Int64 index = (*arguments[j + 1].column)[row].get(); if (!moveToElementByIndex(res_element, index, key)) return false; break; } case MoveType::Key: { - key = std::string_view{(*columns[arguments[j + 1]].column).getDataAt(row)}; + key = std::string_view{(*arguments[j + 1].column).getDataAt(row)}; if (!moveToElementByKey(res_element, key)) return false; break; @@ -286,21 +286,18 @@ public: return Impl::getReturnType(Name::name, arguments); } - void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result_pos, size_t input_rows_count) const override + ColumnPtr executeImpl(ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override { /// Choose JSONParser. #if USE_SIMDJSON if (context.getSettingsRef().allow_simdjson) - { - FunctionJSONHelpers::Executor::run(columns, arguments, result_pos, input_rows_count); - return; - } + return FunctionJSONHelpers::Executor::run(arguments, result_type, input_rows_count); #endif #if USE_RAPIDJSON - FunctionJSONHelpers::Executor::run(columns, arguments, result_pos, input_rows_count); + return FunctionJSONHelpers::Executor::run(arguments, result_type, input_rows_count); #else - FunctionJSONHelpers::Executor::run(columns, arguments, result_pos, input_rows_count); + return FunctionJSONHelpers::Executor::run(arguments, result_type, input_rows_count); #endif } @@ -334,7 +331,7 @@ public: static DataTypePtr getReturnType(const char *, const ColumnsWithTypeAndName &) { return std::make_shared(); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element &, const std::string_view &) { @@ -362,7 +359,7 @@ public: return std::make_shared(); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers &) { return 0; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &) { return 0; } static bool insertResultToColumn(IColumn & dest, const Element &, const std::string_view &) { @@ -386,7 +383,7 @@ public: return std::make_shared(); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) { @@ -416,7 +413,7 @@ public: return std::make_shared(); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element &, const std::string_view & last_key) { @@ -450,7 +447,7 @@ public: return std::make_shared>(values); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) { @@ -492,7 +489,7 @@ public: return std::make_shared>(); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) { @@ -557,7 +554,7 @@ public: return std::make_shared(); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) { @@ -582,7 +579,7 @@ public: return std::make_shared(); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) { @@ -909,11 +906,11 @@ public: return DataTypeFactory::instance().get(col_type_const->getValue()); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 2; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 2; } - void prepare(const char * function_name, const ColumnsWithTypeAndName & columns, const ColumnNumbers &, size_t result_pos) + void prepare(const char * function_name, const ColumnsWithTypeAndName &, const DataTypePtr & result_type) { - extract_tree = JSONExtractTree::build(function_name, columns[result_pos].type); + extract_tree = JSONExtractTree::build(function_name, result_type); } bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) @@ -950,11 +947,10 @@ public: return std::make_unique(tuple_type); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 2; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 2; } - void prepare(const char * function_name, const ColumnsWithTypeAndName & columns, const ColumnNumbers &, size_t result_pos) + void prepare(const char * function_name, const ColumnsWithTypeAndName &, const DataTypePtr & result_type) { - const auto & result_type = columns[result_pos].type; const auto tuple_type = typeid_cast(result_type.get())->getNestedType(); const auto value_type = typeid_cast(tuple_type.get())->getElements()[1]; extract_tree = JSONExtractTree::build(function_name, value_type); @@ -1002,7 +998,7 @@ public: return std::make_shared(); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) { @@ -1106,7 +1102,7 @@ public: return std::make_shared(std::make_shared()); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } static bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) { @@ -1138,7 +1134,7 @@ public: return std::make_unique(tuple_type); } - static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName &, const ColumnNumbers & arguments) { return arguments.size() - 1; } + static size_t getNumberOfIndexArguments(const ColumnsWithTypeAndName & arguments) { return arguments.size() - 1; } bool insertResultToColumn(IColumn & dest, const Element & element, const std::string_view &) { diff --git a/src/Functions/FunctionsLogical.cpp b/src/Functions/FunctionsLogical.cpp index e921471497d..5e28c0eaff1 100644 --- a/src/Functions/FunctionsLogical.cpp +++ b/src/Functions/FunctionsLogical.cpp @@ -342,7 +342,7 @@ struct OperationApplier template -static void executeForTernaryLogicImpl(ColumnRawPtrs arguments, ColumnWithTypeAndName & result_info, size_t input_rows_count) +static ColumnPtr executeForTernaryLogicImpl(ColumnRawPtrs arguments, const DataTypePtr & result_type, size_t input_rows_count) { /// Combine all constant columns into a single constant value. UInt8 const_3v_value = 0; @@ -351,11 +351,10 @@ static void executeForTernaryLogicImpl(ColumnRawPtrs arguments, ColumnWithTypeAn /// If the constant value uniquely determines the result, return it. if (has_consts && (arguments.empty() || Op::isSaturatedValueTernary(const_3v_value))) { - result_info.column = ColumnConst::create( - buildColumnFromTernaryData(UInt8Container({const_3v_value}), result_info.type->isNullable()), + return ColumnConst::create( + buildColumnFromTernaryData(UInt8Container({const_3v_value}), result_type->isNullable()), input_rows_count ); - return; } const auto result_column = has_consts ? @@ -363,7 +362,7 @@ static void executeForTernaryLogicImpl(ColumnRawPtrs arguments, ColumnWithTypeAn OperationApplier::apply(arguments, result_column->getData(), has_consts); - result_info.column = buildColumnFromTernaryData(result_column->getData(), result_info.type->isNullable()); + return buildColumnFromTernaryData(result_column->getData(), result_type->isNullable()); } @@ -418,7 +417,7 @@ struct TypedExecutorInvoker /// Types of all of the arguments are guaranteed to be non-nullable here template -static void basicExecuteImpl(ColumnRawPtrs arguments, ColumnWithTypeAndName & result_info, size_t input_rows_count) +static ColumnPtr basicExecuteImpl(ColumnRawPtrs arguments, size_t input_rows_count) { /// Combine all constant columns into a single constant value. UInt8 const_val = 0; @@ -429,8 +428,7 @@ static void basicExecuteImpl(ColumnRawPtrs arguments, ColumnWithTypeAndName & re { if (!arguments.empty()) const_val = Op::apply(const_val, 0); - result_info.column = DataTypeUInt8().createColumnConst(input_rows_count, toField(const_val)); - return; + return DataTypeUInt8().createColumnConst(input_rows_count, toField(const_val)); } /// If the constant value is a neutral element, let's forget about it. @@ -448,8 +446,7 @@ static void basicExecuteImpl(ColumnRawPtrs arguments, ColumnWithTypeAndName & re else FastApplierImpl::apply(*arguments[0], *arguments[1], col_res->getData()); - result_info.column = std::move(col_res); - return; + return col_res; } /// Convert all columns to UInt8 @@ -470,7 +467,7 @@ static void basicExecuteImpl(ColumnRawPtrs arguments, ColumnWithTypeAndName & re OperationApplier::apply(uint8_args, col_res->getData(), has_consts); - result_info.column = std::move(col_res); + return col_res; } } @@ -511,18 +508,17 @@ DataTypePtr FunctionAnyArityLogical::getReturnTypeImpl(const DataTyp } template -void FunctionAnyArityLogical::executeImpl( - ColumnsWithTypeAndName & columns, const ColumnNumbers & arguments, size_t result_index, size_t input_rows_count) const +ColumnPtr FunctionAnyArityLogical::executeImpl( + ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const { ColumnRawPtrs args_in; - for (const auto arg_index : arguments) - args_in.push_back(columns[arg_index].column.get()); + for (const auto & arg_index : arguments) + args_in.push_back(arg_index.column.get()); - auto & result_info = columns[result_index]; - if (result_info.type->isNullable()) - executeForTernaryLogicImpl(std::move(args_in), result_info, input_rows_count); + if (result_type->isNullable()) + return executeForTernaryLogicImpl(std::move(args_in), result_type, input_rows_count); else - basicExecuteImpl(std::move(args_in), result_info, input_rows_count); + return basicExecuteImpl(std::move(args_in), input_rows_count); } @@ -554,9 +550,9 @@ DataTypePtr FunctionUnaryLogical::getReturnTypeImpl(const DataTypes } template