diff --git a/src/Functions/monthName.cpp b/src/Functions/monthName.cpp index 68675aef20d..c397fdffaa5 100644 --- a/src/Functions/monthName.cpp +++ b/src/Functions/monthName.cpp @@ -5,22 +5,25 @@ namespace DB { + namespace ErrorCodes { extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int ILLEGAL_TYPE_OF_ARGUMENT; } -class FunctionMonthNameImpl : public IFunction +class FunctionMonthName : public IFunction { public: static constexpr auto name = "monthName"; static constexpr auto month_str = "month"; - static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } + static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } - explicit FunctionMonthNameImpl(ContextPtr context_) : context(context_) {} + explicit FunctionMonthName(ContextPtr context_) + : function_resolver(FunctionFactory::instance().get("dateName", std::move(context_))) + {} String getName() const override { return name; } @@ -61,17 +64,17 @@ public: arguments[0] }; - auto date_name_func = FunctionFactory::instance().get("dateName", context)->build(temporary_columns); + auto date_name_func = function_resolver->build(temporary_columns); return date_name_func->execute(temporary_columns, result_type, input_rows_count); } private: - ContextPtr context; + FunctionOverloadResolverPtr function_resolver; }; void registerFunctionMonthName(FunctionFactory & factory) { - factory.registerFunction(FunctionFactory::CaseInsensitive); + factory.registerFunction(FunctionFactory::CaseInsensitive); } } diff --git a/tests/queries/0_stateless/02160_monthname.sql b/tests/queries/0_stateless/02160_monthname.sql index 57cdab6f7ac..2c5bd5b576b 100644 --- a/tests/queries/0_stateless/02160_monthname.sql +++ b/tests/queries/0_stateless/02160_monthname.sql @@ -69,4 +69,3 @@ WITH toDateTime('2021-12-14 11:22:33') AS date_time_value, toDateTime64('2021-12-14 11:22:33', 3) AS date_time_64_value SELECT monthName(date_value), monthName(date_time_value), monthName(date_time_64_value); -