mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-17 20:02:05 +00:00
Remove wasteful template instatiations
This commit is contained in:
parent
fb552dd2c0
commit
ec776fe8db
@ -87,6 +87,77 @@ static bool callOnBasicType(TypeIndex number, F && f)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, bool _int, bool _float, bool _decimal, bool _datetime, typename F>
|
||||
static bool callOnBasicTypeSecondArg(TypeIndex number, F && f)
|
||||
{
|
||||
if constexpr (_int)
|
||||
{
|
||||
switch (number)
|
||||
{
|
||||
case TypeIndex::UInt8: return f(TypePair<UInt8, T>());
|
||||
case TypeIndex::UInt16: return f(TypePair<UInt16, T>());
|
||||
case TypeIndex::UInt32: return f(TypePair<UInt32, T>());
|
||||
case TypeIndex::UInt64: return f(TypePair<UInt64, T>());
|
||||
case TypeIndex::UInt128: return f(TypePair<UInt128, T>());
|
||||
case TypeIndex::UInt256: return f(TypePair<UInt256, T>());
|
||||
|
||||
case TypeIndex::Int8: return f(TypePair<Int8, T>());
|
||||
case TypeIndex::Int16: return f(TypePair<Int16, T>());
|
||||
case TypeIndex::Int32: return f(TypePair<Int32, T>());
|
||||
case TypeIndex::Int64: return f(TypePair<Int64, T>());
|
||||
case TypeIndex::Int128: return f(TypePair<Int128, T>());
|
||||
case TypeIndex::Int256: return f(TypePair<Int256, T>());
|
||||
|
||||
case TypeIndex::Enum8: return f(TypePair<Int8, T>());
|
||||
case TypeIndex::Enum16: return f(TypePair<Int16, T>());
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (_decimal)
|
||||
{
|
||||
switch (number)
|
||||
{
|
||||
case TypeIndex::Decimal32: return f(TypePair<Decimal32, T>());
|
||||
case TypeIndex::Decimal64: return f(TypePair<Decimal64, T>());
|
||||
case TypeIndex::Decimal128: return f(TypePair<Decimal128, T>());
|
||||
case TypeIndex::Decimal256: return f(TypePair<Decimal256, T>());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (_float)
|
||||
{
|
||||
switch (number)
|
||||
{
|
||||
case TypeIndex::BFloat16: return f(TypePair<BFloat16, T>());
|
||||
case TypeIndex::Float32: return f(TypePair<Float32, T>());
|
||||
case TypeIndex::Float64: return f(TypePair<Float64, T>());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (_datetime)
|
||||
{
|
||||
switch (number)
|
||||
{
|
||||
case TypeIndex::Date: return f(TypePair<UInt16, T>());
|
||||
case TypeIndex::Date32: return f(TypePair<Int32, T>());
|
||||
case TypeIndex::DateTime: return f(TypePair<UInt32, T>());
|
||||
case TypeIndex::DateTime64: return f(TypePair<DateTime64, T>());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Unroll template using TypeIndex
|
||||
template <bool _int, bool _float, bool _decimal, bool _datetime, typename F>
|
||||
static inline bool callOnBasicTypes(TypeIndex type_num1, TypeIndex type_num2, F && f)
|
||||
|
@ -50,6 +50,44 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
template <bool _int, bool _float, bool _decimal, bool _datetime, typename F>
|
||||
static inline bool callOnAtLeastOneDecimalType(TypeIndex type_num1, TypeIndex type_num2, F && f)
|
||||
{
|
||||
switch (type_num1)
|
||||
{
|
||||
case TypeIndex::Decimal32:
|
||||
return callOnBasicType<Decimal32, _int, _float, _decimal, _datetime>(type_num2, std::forward<F>(f));
|
||||
case TypeIndex::Decimal64:
|
||||
return callOnBasicType<Decimal64, _int, _float, _decimal, _datetime>(type_num2, std::forward<F>(f));
|
||||
case TypeIndex::Decimal128:
|
||||
return callOnBasicType<Decimal128, _int, _float, _decimal, _datetime>(type_num2, std::forward<F>(f));
|
||||
case TypeIndex::Decimal256:
|
||||
return callOnBasicType<Decimal256, _int, _float, _decimal, _datetime>(type_num2, std::forward<F>(f));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (type_num2)
|
||||
{
|
||||
case TypeIndex::Decimal32:
|
||||
return callOnBasicTypeSecondArg<Decimal32, _int, _float, _decimal, _datetime>(type_num1, std::forward<F>(f));
|
||||
case TypeIndex::Decimal64:
|
||||
return callOnBasicTypeSecondArg<Decimal64, _int, _float, _decimal, _datetime>(type_num1, std::forward<F>(f));
|
||||
case TypeIndex::Decimal128:
|
||||
return callOnBasicTypeSecondArg<Decimal128, _int, _float, _decimal, _datetime>(type_num1, std::forward<F>(f));
|
||||
case TypeIndex::Decimal256:
|
||||
return callOnBasicTypeSecondArg<Decimal256, _int, _float, _decimal, _datetime>(type_num1, std::forward<F>(f));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int ILLEGAL_COLUMN;
|
||||
@ -770,7 +808,7 @@ private:
|
||||
return (res = DecimalComparison<LeftDataType, RightDataType, Op, false>::apply(col_left, col_right)) != nullptr;
|
||||
};
|
||||
|
||||
if (!callOnBasicTypes<true, false, true, true>(left_number, right_number, call))
|
||||
if (!callOnAtLeastOneDecimalType<true, false, true, true>(left_number, right_number, call))
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong call for {} with {} and {}",
|
||||
getName(), col_left.type->getName(), col_right.type->getName());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user