From dc7f4b39eef4c2a9b47cee7b7197c58fd86c0520 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 9 Mar 2024 07:00:28 +0100 Subject: [PATCH] Remove garbage --- src/Functions/CMakeLists.txt | 2 - .../CastInternalOverloadResolverImpl.cpp | 10 --- src/Functions/CastOverloadResolver.cpp | 21 +----- src/Functions/CastOverloadResolverImpl.cpp | 10 --- src/Functions/CastOverloadResolverImpl.h | 73 +++++++------------ 5 files changed, 31 insertions(+), 85 deletions(-) delete mode 100644 src/Functions/CastInternalOverloadResolverImpl.cpp delete mode 100644 src/Functions/CastOverloadResolverImpl.cpp diff --git a/src/Functions/CMakeLists.txt b/src/Functions/CMakeLists.txt index f27bcae1fe3..ac3e3671ae0 100644 --- a/src/Functions/CMakeLists.txt +++ b/src/Functions/CMakeLists.txt @@ -15,8 +15,6 @@ extract_into_parent_list(clickhouse_functions_sources dbms_sources checkHyperscanRegexp.cpp array/has.cpp CastOverloadResolver.cpp - CastOverloadResolverImpl.cpp - CastInternalOverloadResolverImpl.cpp ) extract_into_parent_list(clickhouse_functions_headers dbms_headers IFunction.h diff --git a/src/Functions/CastInternalOverloadResolverImpl.cpp b/src/Functions/CastInternalOverloadResolverImpl.cpp deleted file mode 100644 index 8b74f76ca39..00000000000 --- a/src/Functions/CastInternalOverloadResolverImpl.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -namespace DB -{ - -template class CastOverloadResolverImpl; -template class CastOverloadResolverImpl; -template class CastOverloadResolverImpl; - -} diff --git a/src/Functions/CastOverloadResolver.cpp b/src/Functions/CastOverloadResolver.cpp index 6bacc7f4847..79b17d3297c 100644 --- a/src/Functions/CastOverloadResolver.cpp +++ b/src/Functions/CastOverloadResolver.cpp @@ -26,27 +26,14 @@ UInt32 extractToDecimalScale(const ColumnWithTypeAndName & named_column) return static_cast(field.get()); } -FunctionOverloadResolverPtr createInternalCastOverloadResolver(CastType type, std::optional diagnostic) -{ - switch (type) - { - case CastType::nonAccurate: - return CastInternalOverloadResolver::createImpl(diagnostic); - case CastType::accurate: - return CastInternalOverloadResolver::createImpl(diagnostic); - case CastType::accurateOrNull: - return CastInternalOverloadResolver::createImpl(diagnostic); - } -} - REGISTER_FUNCTION(CastOverloadResolvers) { - factory.registerFunction>({}, FunctionFactory::CaseInsensitive); + factory.registerFunction("_CAST", [](ContextPtr context){ return CastOverloadResolverImpl::create(context, CastType::nonAccurate, true); }, {}, FunctionFactory::CaseInsensitive); /// Note: "internal" (not affected by null preserving setting) versions of accurate cast functions are unneeded. - factory.registerFunction>({}, FunctionFactory::CaseInsensitive); - factory.registerFunction>(); - factory.registerFunction>(); + factory.registerFunction("CAST", [](ContextPtr context){ return CastOverloadResolverImpl::create(context, CastType::nonAccurate, false); }, {}, FunctionFactory::CaseInsensitive); + factory.registerFunction("accurateCast", [](ContextPtr context){ return CastOverloadResolverImpl::create(context, CastType::accurate, false); }, {}); + factory.registerFunction("accurateCastOrNull", [](ContextPtr context){ return CastOverloadResolverImpl::create(context, CastType::accurateOrNull, false); }, {}); } } diff --git a/src/Functions/CastOverloadResolverImpl.cpp b/src/Functions/CastOverloadResolverImpl.cpp deleted file mode 100644 index a7f7024892e..00000000000 --- a/src/Functions/CastOverloadResolverImpl.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -namespace DB -{ - -template class CastOverloadResolverImpl; -template class CastOverloadResolverImpl; -template class CastOverloadResolverImpl; - -} diff --git a/src/Functions/CastOverloadResolverImpl.h b/src/Functions/CastOverloadResolverImpl.h index 36376c5f254..b3f3e50ebf8 100644 --- a/src/Functions/CastOverloadResolverImpl.h +++ b/src/Functions/CastOverloadResolverImpl.h @@ -29,55 +29,48 @@ struct CastInternalName * Cast preserves nullability according to setting `cast_keep_nullable`, * i.e. Cast(toNullable(toInt8(1)) as Int32) will be Nullable(Int32(1)) if `cast_keep_nullable` == 1. */ -template class CastOverloadResolverImpl : public IFunctionOverloadResolver { public: using MonotonicityForRange = FunctionCastBase::MonotonicityForRange; - static constexpr auto name = cast_type == CastType::accurate - ? "accurateCast" - : (cast_type == CastType::accurateOrNull ? "accurateCastOrNull" - : (internal ? "_CAST" : "CAST")); - - String getName() const override { return name; } + String getName() const override + { + if (cast_type == CastType::accurate) + return "accurateCast"; + if (cast_type == CastType::accurateOrNull) + return "accurateCastOrNull"; + if (internal) + return "_CAST"; + else + return "CAST"; + } size_t getNumberOfArguments() const override { return 2; } ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1}; } - explicit CastOverloadResolverImpl(ContextPtr context_, std::optional diagnostic_, bool keep_nullable_, const DataTypeValidationSettings & data_type_validation_settings_) + explicit CastOverloadResolverImpl(ContextPtr context_, CastType cast_type_, bool internal_, std::optional diagnostic_, bool keep_nullable_, const DataTypeValidationSettings & data_type_validation_settings_) : context(context_) + , cast_type(cast_type_) + , internal(internal_) , diagnostic(std::move(diagnostic_)) , keep_nullable(keep_nullable_) , data_type_validation_settings(data_type_validation_settings_) { } - static FunctionOverloadResolverPtr create(ContextPtr context) + static FunctionOverloadResolverPtr create(ContextPtr context, CastType cast_type, bool internal) { const auto & settings_ref = context->getSettingsRef(); - if constexpr (internal) - return createImpl(context, {}, false /*keep_nullable*/); - - return createImpl(context, {}, settings_ref.cast_keep_nullable, DataTypeValidationSettings(settings_ref)); - } - - static FunctionOverloadResolverPtr createImpl(ContextPtr context, std::optional diagnostic = {}, bool keep_nullable = false, const DataTypeValidationSettings & data_type_validation_settings = {}) - { - assert(!internal || !keep_nullable); - return std::make_unique(context, std::move(diagnostic), keep_nullable, data_type_validation_settings); - } - - static FunctionOverloadResolverPtr createImpl(std::optional diagnostic = {}, bool keep_nullable = false, const DataTypeValidationSettings & data_type_validation_settings = {}) - { - assert(!internal || !keep_nullable); - return std::make_unique(ContextPtr(), std::move(diagnostic), keep_nullable, data_type_validation_settings); + if (internal) + return std::make_unique(context, cast_type, internal, std::nullopt, false /*keep_nullable*/, DataTypeValidationSettings{}); + else + return std::make_unique(context, cast_type, internal, std::nullopt, settings_ref.cast_keep_nullable, DataTypeValidationSettings(settings_ref)); } protected: - FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & return_type) const override { DataTypes data_types(arguments.size()); @@ -87,8 +80,10 @@ protected: auto monotonicity = MonotonicityHelper::getMonotonicityInformation(arguments.front().type, return_type.get()); - using Function = FunctionCast>; - return std::make_unique(context, name, std::move(monotonicity), data_types, return_type, diagnostic, cast_type); + if (internal) + return std::make_unique>(context, CastInternalName::name, std::move(monotonicity), data_types, return_type, diagnostic, cast_type); + else + return std::make_unique>(context, CastName::name, std::move(monotonicity), data_types, return_type, diagnostic, cast_type); } DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override @@ -106,10 +101,10 @@ protected: DataTypePtr type = DataTypeFactory::instance().get(type_col->getValue()); validateDataType(type, data_type_validation_settings); - if constexpr (cast_type == CastType::accurateOrNull) + if (cast_type == CastType::accurateOrNull) return makeNullable(type); - if constexpr (internal) + if (internal) return type; if (keep_nullable && arguments.front().type->isNullable() && type->canBeInsideNullable()) @@ -124,25 +119,11 @@ protected: private: ContextPtr context; + CastType cast_type; + bool internal; std::optional diagnostic; bool keep_nullable; DataTypeValidationSettings data_type_validation_settings; }; - -template -using CastOverloadResolver = CastOverloadResolverImpl; - -template -using CastInternalOverloadResolver = CastOverloadResolverImpl; - - -extern template class CastOverloadResolverImpl; -extern template class CastOverloadResolverImpl; -extern template class CastOverloadResolverImpl; - -extern template class CastOverloadResolverImpl; -extern template class CastOverloadResolverImpl; -extern template class CastOverloadResolverImpl; - }