From c646f5649ce2d7af41829ef260b90eb79ef5cfbc Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 10 Sep 2018 05:36:33 +0300 Subject: [PATCH] Every function in its own file, part 3 --- dbms/src/Functions/concat.cpp | 19 ++++++++++++------- dbms/src/Functions/reverse.cpp | 12 ++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/dbms/src/Functions/concat.cpp b/dbms/src/Functions/concat.cpp index 84814bfbe8c..67bf020e340 100644 --- a/dbms/src/Functions/concat.cpp +++ b/dbms/src/Functions/concat.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace DB @@ -157,21 +158,25 @@ public: bool isVariadic() const override { return true; } protected: - FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*return_type*/) const override + FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & return_type) const override { if (isArray(arguments.at(0).type)) return FunctionFactory::instance().get("arrayConcat", context)->build(arguments); else - return FunctionConcat::create(context); + return std::make_shared( + FunctionConcat::create(context), + ext::map(arguments, [](const auto & elem) { return elem.type; }), + return_type); } - DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override + DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - DataTypes arg_types; - for (const auto & arg : arguments) - arg_types.emplace_back(arg.type); + if (arguments.size() < 2) + throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " + toString(arguments.size()) + + ", should be at least 2.", + ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - return getLeastSupertype(arg_types); + return getLeastSupertype(arguments); } private: diff --git a/dbms/src/Functions/reverse.cpp b/dbms/src/Functions/reverse.cpp index b6cad7eb67e..e9327f58f61 100644 --- a/dbms/src/Functions/reverse.cpp +++ b/dbms/src/Functions/reverse.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace DB @@ -123,17 +124,20 @@ public: size_t getNumberOfArguments() const override { return 1; } protected: - FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*return_type*/) const override + FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & return_type) const override { if (isArray(arguments.at(0).type)) return FunctionFactory::instance().get("arrayReverse", context)->build(arguments); else - return FunctionReverse::create(context); + return std::make_shared( + FunctionReverse::create(context), + ext::map(arguments, [](const auto & elem) { return elem.type; }), + return_type); } - DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override + DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { - return arguments.at(0).type; + return arguments.at(0); } private: