Remove garbage

This commit is contained in:
Alexey Milovidov 2024-03-09 07:00:28 +01:00
parent 0d05b8ccc1
commit dc7f4b39ee
5 changed files with 31 additions and 85 deletions

View File

@ -15,8 +15,6 @@ extract_into_parent_list(clickhouse_functions_sources dbms_sources
checkHyperscanRegexp.cpp checkHyperscanRegexp.cpp
array/has.cpp array/has.cpp
CastOverloadResolver.cpp CastOverloadResolver.cpp
CastOverloadResolverImpl.cpp
CastInternalOverloadResolverImpl.cpp
) )
extract_into_parent_list(clickhouse_functions_headers dbms_headers extract_into_parent_list(clickhouse_functions_headers dbms_headers
IFunction.h IFunction.h

View File

@ -1,10 +0,0 @@
#include <Functions/CastOverloadResolverImpl.h>
namespace DB
{
template class CastOverloadResolverImpl<CastType::nonAccurate, true>;
template class CastOverloadResolverImpl<CastType::accurate, true>;
template class CastOverloadResolverImpl<CastType::accurateOrNull, true>;
}

View File

@ -26,27 +26,14 @@ UInt32 extractToDecimalScale(const ColumnWithTypeAndName & named_column)
return static_cast<UInt32>(field.get<UInt32>()); return static_cast<UInt32>(field.get<UInt32>());
} }
FunctionOverloadResolverPtr createInternalCastOverloadResolver(CastType type, std::optional<CastDiagnostic> diagnostic)
{
switch (type)
{
case CastType::nonAccurate:
return CastInternalOverloadResolver<CastType::nonAccurate>::createImpl(diagnostic);
case CastType::accurate:
return CastInternalOverloadResolver<CastType::accurate>::createImpl(diagnostic);
case CastType::accurateOrNull:
return CastInternalOverloadResolver<CastType::accurateOrNull>::createImpl(diagnostic);
}
}
REGISTER_FUNCTION(CastOverloadResolvers) REGISTER_FUNCTION(CastOverloadResolvers)
{ {
factory.registerFunction<CastInternalOverloadResolver<CastType::nonAccurate>>({}, 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. /// Note: "internal" (not affected by null preserving setting) versions of accurate cast functions are unneeded.
factory.registerFunction<CastOverloadResolver<CastType::nonAccurate>>({}, FunctionFactory::CaseInsensitive); factory.registerFunction("CAST", [](ContextPtr context){ return CastOverloadResolverImpl::create(context, CastType::nonAccurate, false); }, {}, FunctionFactory::CaseInsensitive);
factory.registerFunction<CastOverloadResolver<CastType::accurate>>(); factory.registerFunction("accurateCast", [](ContextPtr context){ return CastOverloadResolverImpl::create(context, CastType::accurate, false); }, {});
factory.registerFunction<CastOverloadResolver<CastType::accurateOrNull>>(); factory.registerFunction("accurateCastOrNull", [](ContextPtr context){ return CastOverloadResolverImpl::create(context, CastType::accurateOrNull, false); }, {});
} }
} }

View File

@ -1,10 +0,0 @@
#include <Functions/CastOverloadResolverImpl.h>
namespace DB
{
template class CastOverloadResolverImpl<CastType::nonAccurate, false>;
template class CastOverloadResolverImpl<CastType::accurate, false>;
template class CastOverloadResolverImpl<CastType::accurateOrNull, false>;
}

View File

@ -29,55 +29,48 @@ struct CastInternalName
* Cast preserves nullability according to setting `cast_keep_nullable`, * 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. * i.e. Cast(toNullable(toInt8(1)) as Int32) will be Nullable(Int32(1)) if `cast_keep_nullable` == 1.
*/ */
template <CastType cast_type, bool internal>
class CastOverloadResolverImpl : public IFunctionOverloadResolver class CastOverloadResolverImpl : public IFunctionOverloadResolver
{ {
public: public:
using MonotonicityForRange = FunctionCastBase::MonotonicityForRange; using MonotonicityForRange = FunctionCastBase::MonotonicityForRange;
static constexpr auto name = cast_type == CastType::accurate String getName() const override
? "accurateCast" {
: (cast_type == CastType::accurateOrNull ? "accurateCastOrNull" if (cast_type == CastType::accurate)
: (internal ? "_CAST" : "CAST")); return "accurateCast";
if (cast_type == CastType::accurateOrNull)
String getName() const override { return name; } return "accurateCastOrNull";
if (internal)
return "_CAST";
else
return "CAST";
}
size_t getNumberOfArguments() const override { return 2; } size_t getNumberOfArguments() const override { return 2; }
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1}; } ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1}; }
explicit CastOverloadResolverImpl(ContextPtr context_, std::optional<CastDiagnostic> diagnostic_, bool keep_nullable_, const DataTypeValidationSettings & data_type_validation_settings_) explicit CastOverloadResolverImpl(ContextPtr context_, CastType cast_type_, bool internal_, std::optional<CastDiagnostic> diagnostic_, bool keep_nullable_, const DataTypeValidationSettings & data_type_validation_settings_)
: context(context_) : context(context_)
, cast_type(cast_type_)
, internal(internal_)
, diagnostic(std::move(diagnostic_)) , diagnostic(std::move(diagnostic_))
, keep_nullable(keep_nullable_) , keep_nullable(keep_nullable_)
, data_type_validation_settings(data_type_validation_settings_) , 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(); const auto & settings_ref = context->getSettingsRef();
if constexpr (internal) if (internal)
return createImpl(context, {}, false /*keep_nullable*/); return std::make_unique<CastOverloadResolverImpl>(context, cast_type, internal, std::nullopt, false /*keep_nullable*/, DataTypeValidationSettings{});
else
return createImpl(context, {}, settings_ref.cast_keep_nullable, DataTypeValidationSettings(settings_ref)); return std::make_unique<CastOverloadResolverImpl>(context, cast_type, internal, std::nullopt, settings_ref.cast_keep_nullable, DataTypeValidationSettings(settings_ref));
}
static FunctionOverloadResolverPtr createImpl(ContextPtr context, std::optional<CastDiagnostic> diagnostic = {}, bool keep_nullable = false, const DataTypeValidationSettings & data_type_validation_settings = {})
{
assert(!internal || !keep_nullable);
return std::make_unique<CastOverloadResolverImpl>(context, std::move(diagnostic), keep_nullable, data_type_validation_settings);
}
static FunctionOverloadResolverPtr createImpl(std::optional<CastDiagnostic> diagnostic = {}, bool keep_nullable = false, const DataTypeValidationSettings & data_type_validation_settings = {})
{
assert(!internal || !keep_nullable);
return std::make_unique<CastOverloadResolverImpl>(ContextPtr(), std::move(diagnostic), keep_nullable, data_type_validation_settings);
} }
protected: protected:
FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & return_type) const override FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & return_type) const override
{ {
DataTypes data_types(arguments.size()); DataTypes data_types(arguments.size());
@ -87,8 +80,10 @@ protected:
auto monotonicity = MonotonicityHelper::getMonotonicityInformation(arguments.front().type, return_type.get()); auto monotonicity = MonotonicityHelper::getMonotonicityInformation(arguments.front().type, return_type.get());
using Function = FunctionCast<std::conditional_t<internal, CastInternalName, CastName>>; if (internal)
return std::make_unique<Function>(context, name, std::move(monotonicity), data_types, return_type, diagnostic, cast_type); return std::make_unique<FunctionCast<CastInternalName>>(context, CastInternalName::name, std::move(monotonicity), data_types, return_type, diagnostic, cast_type);
else
return std::make_unique<FunctionCast<CastName>>(context, CastName::name, std::move(monotonicity), data_types, return_type, diagnostic, cast_type);
} }
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
@ -106,10 +101,10 @@ protected:
DataTypePtr type = DataTypeFactory::instance().get(type_col->getValue<String>()); DataTypePtr type = DataTypeFactory::instance().get(type_col->getValue<String>());
validateDataType(type, data_type_validation_settings); validateDataType(type, data_type_validation_settings);
if constexpr (cast_type == CastType::accurateOrNull) if (cast_type == CastType::accurateOrNull)
return makeNullable(type); return makeNullable(type);
if constexpr (internal) if (internal)
return type; return type;
if (keep_nullable && arguments.front().type->isNullable() && type->canBeInsideNullable()) if (keep_nullable && arguments.front().type->isNullable() && type->canBeInsideNullable())
@ -124,25 +119,11 @@ protected:
private: private:
ContextPtr context; ContextPtr context;
CastType cast_type;
bool internal;
std::optional<CastDiagnostic> diagnostic; std::optional<CastDiagnostic> diagnostic;
bool keep_nullable; bool keep_nullable;
DataTypeValidationSettings data_type_validation_settings; DataTypeValidationSettings data_type_validation_settings;
}; };
template <CastType cast_type>
using CastOverloadResolver = CastOverloadResolverImpl<cast_type, false>;
template <CastType cast_type>
using CastInternalOverloadResolver = CastOverloadResolverImpl<cast_type, true>;
extern template class CastOverloadResolverImpl<CastType::nonAccurate, false>;
extern template class CastOverloadResolverImpl<CastType::accurate, false>;
extern template class CastOverloadResolverImpl<CastType::accurateOrNull, false>;
extern template class CastOverloadResolverImpl<CastType::nonAccurate, true>;
extern template class CastOverloadResolverImpl<CastType::accurate, true>;
extern template class CastOverloadResolverImpl<CastType::accurateOrNull, true>;
} }