2015-09-24 12:40:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-10 17:09:07 +00:00
|
|
|
#include <DataTypes/IDataType.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <AggregateFunctions/IAggregateFunction.h>
|
2015-12-22 12:03:21 +00:00
|
|
|
|
2020-08-19 11:52:17 +00:00
|
|
|
#define FOR_BASIC_NUMERIC_TYPES(M) \
|
|
|
|
M(UInt8) \
|
|
|
|
M(UInt16) \
|
|
|
|
M(UInt32) \
|
|
|
|
M(UInt64) \
|
|
|
|
M(Int8) \
|
|
|
|
M(Int16) \
|
|
|
|
M(Int32) \
|
|
|
|
M(Int64) \
|
|
|
|
M(Float32) \
|
|
|
|
M(Float64)
|
|
|
|
|
2017-12-20 21:22:04 +00:00
|
|
|
#define FOR_NUMERIC_TYPES(M) \
|
|
|
|
M(UInt8) \
|
|
|
|
M(UInt16) \
|
|
|
|
M(UInt32) \
|
|
|
|
M(UInt64) \
|
2020-09-01 09:54:50 +00:00
|
|
|
M(UInt256) \
|
2017-12-20 21:22:04 +00:00
|
|
|
M(Int8) \
|
|
|
|
M(Int16) \
|
|
|
|
M(Int32) \
|
|
|
|
M(Int64) \
|
2020-08-19 11:52:17 +00:00
|
|
|
M(Int128) \
|
2020-09-01 09:54:50 +00:00
|
|
|
M(Int256) \
|
2017-12-20 21:22:04 +00:00
|
|
|
M(Float32) \
|
|
|
|
M(Float64)
|
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-03-09 00:56:38 +00:00
|
|
|
/** Create an aggregate function with a numeric type in the template parameter, depending on the type of the argument.
|
2015-09-24 12:40:36 +00:00
|
|
|
*/
|
2019-02-09 20:17:20 +00:00
|
|
|
template <template <typename> class AggregateFunctionTemplate, typename... TArgs>
|
2017-12-20 07:36:30 +00:00
|
|
|
static IAggregateFunction * createWithNumericType(const IDataType & argument_type, TArgs && ... args)
|
2015-09-24 12:40:36 +00:00
|
|
|
{
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(argument_type);
|
2018-09-10 17:51:25 +00:00
|
|
|
#define DISPATCH(TYPE) \
|
|
|
|
if (which.idx == TypeIndex::TYPE) return new AggregateFunctionTemplate<TYPE>(std::forward<TArgs>(args)...);
|
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
2017-12-20 21:22:04 +00:00
|
|
|
#undef DISPATCH
|
2018-12-26 03:32:18 +00:00
|
|
|
if (which.idx == TypeIndex::Enum8) return new AggregateFunctionTemplate<Int8>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Enum16) return new AggregateFunctionTemplate<Int16>(std::forward<TArgs>(args)...);
|
2017-12-20 08:14:33 +00:00
|
|
|
return nullptr;
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 20:13:07 +00:00
|
|
|
template <template <typename> class AggregateFunctionTemplate, template <typename> class Data, typename... TArgs>
|
|
|
|
static IAggregateFunction * createWithNumericType(const IDataType & argument_type, TArgs && ... args)
|
|
|
|
{
|
|
|
|
WhichDataType which(argument_type);
|
|
|
|
#define DISPATCH(TYPE) \
|
|
|
|
if (which.idx == TypeIndex::TYPE) return new AggregateFunctionTemplate<Data<TYPE>>(std::forward<TArgs>(args)...);
|
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
|
|
|
#undef DISPATCH
|
|
|
|
if (which.idx == TypeIndex::Enum8) return new AggregateFunctionTemplate<Data<Int8>>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Enum16) return new AggregateFunctionTemplate<Data<Int16>>(std::forward<TArgs>(args)...);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-10 21:01:26 +00:00
|
|
|
template <template <typename, bool> class AggregateFunctionTemplate, bool bool_param, typename... TArgs>
|
|
|
|
static IAggregateFunction * createWithNumericType(const IDataType & argument_type, TArgs && ... args)
|
|
|
|
{
|
|
|
|
WhichDataType which(argument_type);
|
|
|
|
#define DISPATCH(TYPE) \
|
|
|
|
if (which.idx == TypeIndex::TYPE) return new AggregateFunctionTemplate<TYPE, bool_param>(std::forward<TArgs>(args)...);
|
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
|
|
|
#undef DISPATCH
|
|
|
|
if (which.idx == TypeIndex::Enum8) return new AggregateFunctionTemplate<Int8, bool_param>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Enum16) return new AggregateFunctionTemplate<Int16, bool_param>(std::forward<TArgs>(args)...);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-09 20:17:20 +00:00
|
|
|
template <template <typename, typename> class AggregateFunctionTemplate, typename Data, typename... TArgs>
|
2017-08-11 23:25:03 +00:00
|
|
|
static IAggregateFunction * createWithNumericType(const IDataType & argument_type, TArgs && ... args)
|
2017-07-10 23:30:17 +00:00
|
|
|
{
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(argument_type);
|
2018-09-10 17:51:25 +00:00
|
|
|
#define DISPATCH(TYPE) \
|
|
|
|
if (which.idx == TypeIndex::TYPE) return new AggregateFunctionTemplate<TYPE, Data>(std::forward<TArgs>(args)...);
|
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
2017-12-20 21:22:04 +00:00
|
|
|
#undef DISPATCH
|
2018-12-26 03:32:18 +00:00
|
|
|
if (which.idx == TypeIndex::Enum8) return new AggregateFunctionTemplate<Int8, Data>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Enum16) return new AggregateFunctionTemplate<Int16, Data>(std::forward<TArgs>(args)...);
|
2017-12-20 08:14:33 +00:00
|
|
|
return nullptr;
|
2017-07-10 23:30:17 +00:00
|
|
|
}
|
2015-09-24 12:40:36 +00:00
|
|
|
|
2019-02-09 20:17:20 +00:00
|
|
|
template <template <typename, typename> class AggregateFunctionTemplate, template <typename> class Data, typename... TArgs>
|
2017-12-20 07:36:30 +00:00
|
|
|
static IAggregateFunction * createWithNumericType(const IDataType & argument_type, TArgs && ... args)
|
2015-09-24 12:40:36 +00:00
|
|
|
{
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(argument_type);
|
2018-09-10 17:51:25 +00:00
|
|
|
#define DISPATCH(TYPE) \
|
|
|
|
if (which.idx == TypeIndex::TYPE) return new AggregateFunctionTemplate<TYPE, Data<TYPE>>(std::forward<TArgs>(args)...);
|
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
2017-12-20 21:22:04 +00:00
|
|
|
#undef DISPATCH
|
2018-12-26 03:32:18 +00:00
|
|
|
if (which.idx == TypeIndex::Enum8) return new AggregateFunctionTemplate<Int8, Data<Int8>>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Enum16) return new AggregateFunctionTemplate<Int16, Data<Int16>>(std::forward<TArgs>(args)...);
|
2017-12-20 08:14:33 +00:00
|
|
|
return nullptr;
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 20:17:20 +00:00
|
|
|
template <template <typename, typename> class AggregateFunctionTemplate, template <typename> class Data, typename... TArgs>
|
2017-12-20 07:36:30 +00:00
|
|
|
static IAggregateFunction * createWithUnsignedIntegerType(const IDataType & argument_type, TArgs && ... args)
|
2017-08-30 18:52:14 +00:00
|
|
|
{
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(argument_type);
|
2018-09-10 17:51:25 +00:00
|
|
|
if (which.idx == TypeIndex::UInt8) return new AggregateFunctionTemplate<UInt8, Data<UInt8>>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::UInt16) return new AggregateFunctionTemplate<UInt16, Data<UInt16>>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::UInt32) return new AggregateFunctionTemplate<UInt32, Data<UInt32>>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::UInt64) return new AggregateFunctionTemplate<UInt64, Data<UInt64>>(std::forward<TArgs>(args)...);
|
2017-12-20 08:14:33 +00:00
|
|
|
return nullptr;
|
2017-08-30 18:52:14 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 20:17:20 +00:00
|
|
|
template <template <typename> class AggregateFunctionTemplate, typename... TArgs>
|
2018-10-03 14:22:28 +00:00
|
|
|
static IAggregateFunction * createWithNumericBasedType(const IDataType & argument_type, TArgs && ... args)
|
|
|
|
{
|
|
|
|
IAggregateFunction * f = createWithNumericType<AggregateFunctionTemplate>(argument_type, std::forward<TArgs>(args)...);
|
|
|
|
if (f)
|
|
|
|
return f;
|
|
|
|
|
|
|
|
/// expects that DataTypeDate based on UInt16, DataTypeDateTime based on UInt32 and UUID based on UInt128
|
|
|
|
WhichDataType which(argument_type);
|
|
|
|
if (which.idx == TypeIndex::Date) return new AggregateFunctionTemplate<UInt16>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::DateTime) return new AggregateFunctionTemplate<UInt32>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::UUID) return new AggregateFunctionTemplate<UInt128>(std::forward<TArgs>(args)...);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-09 20:17:20 +00:00
|
|
|
template <template <typename> class AggregateFunctionTemplate, typename... TArgs>
|
2018-09-11 18:42:06 +00:00
|
|
|
static IAggregateFunction * createWithDecimalType(const IDataType & argument_type, TArgs && ... args)
|
|
|
|
{
|
|
|
|
WhichDataType which(argument_type);
|
2018-10-03 14:22:28 +00:00
|
|
|
if (which.idx == TypeIndex::Decimal32) return new AggregateFunctionTemplate<Decimal32>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Decimal64) return new AggregateFunctionTemplate<Decimal64>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Decimal128) return new AggregateFunctionTemplate<Decimal128>(std::forward<TArgs>(args)...);
|
2020-08-19 11:52:17 +00:00
|
|
|
if (which.idx == TypeIndex::Decimal256) return new AggregateFunctionTemplate<Decimal256>(std::forward<TArgs>(args)...);
|
2018-09-11 18:42:06 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-12 05:56:37 +00:00
|
|
|
template <template <typename, typename> class AggregateFunctionTemplate, typename Data, typename... TArgs>
|
|
|
|
static IAggregateFunction * createWithDecimalType(const IDataType & argument_type, TArgs && ... args)
|
|
|
|
{
|
|
|
|
WhichDataType which(argument_type);
|
|
|
|
if (which.idx == TypeIndex::Decimal32) return new AggregateFunctionTemplate<Decimal32, Data>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Decimal64) return new AggregateFunctionTemplate<Decimal64, Data>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Decimal128) return new AggregateFunctionTemplate<Decimal128, Data>(std::forward<TArgs>(args)...);
|
2020-08-19 11:52:17 +00:00
|
|
|
if (which.idx == TypeIndex::Decimal256) return new AggregateFunctionTemplate<Decimal256, Data>(std::forward<TArgs>(args)...);
|
2019-06-12 05:56:37 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-08-30 18:52:14 +00:00
|
|
|
|
2017-03-09 00:56:38 +00:00
|
|
|
/** For template with two arguments.
|
2015-09-24 12:40:36 +00:00
|
|
|
*/
|
2019-02-09 20:17:20 +00:00
|
|
|
template <typename FirstType, template <typename, typename> class AggregateFunctionTemplate, typename... TArgs>
|
2017-12-20 07:36:30 +00:00
|
|
|
static IAggregateFunction * createWithTwoNumericTypesSecond(const IDataType & second_type, TArgs && ... args)
|
2015-09-24 12:40:36 +00:00
|
|
|
{
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(second_type);
|
2018-09-10 17:51:25 +00:00
|
|
|
#define DISPATCH(TYPE) \
|
|
|
|
if (which.idx == TypeIndex::TYPE) return new AggregateFunctionTemplate<FirstType, TYPE>(std::forward<TArgs>(args)...);
|
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
2017-12-20 21:22:04 +00:00
|
|
|
#undef DISPATCH
|
2018-12-26 03:32:18 +00:00
|
|
|
if (which.idx == TypeIndex::Enum8) return new AggregateFunctionTemplate<FirstType, Int8>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::Enum16) return new AggregateFunctionTemplate<FirstType, Int16>(std::forward<TArgs>(args)...);
|
2017-12-20 08:14:33 +00:00
|
|
|
return nullptr;
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 20:17:20 +00:00
|
|
|
template <template <typename, typename> class AggregateFunctionTemplate, typename... TArgs>
|
2017-12-20 07:36:30 +00:00
|
|
|
static IAggregateFunction * createWithTwoNumericTypes(const IDataType & first_type, const IDataType & second_type, TArgs && ... args)
|
2015-09-24 12:40:36 +00:00
|
|
|
{
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(first_type);
|
2018-09-10 17:51:25 +00:00
|
|
|
#define DISPATCH(TYPE) \
|
|
|
|
if (which.idx == TypeIndex::TYPE) \
|
|
|
|
return createWithTwoNumericTypesSecond<TYPE, AggregateFunctionTemplate>(second_type, std::forward<TArgs>(args)...);
|
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
2017-12-20 21:22:04 +00:00
|
|
|
#undef DISPATCH
|
2018-09-10 17:51:25 +00:00
|
|
|
if (which.idx == TypeIndex::Enum8)
|
2018-12-26 03:32:18 +00:00
|
|
|
return createWithTwoNumericTypesSecond<Int8, AggregateFunctionTemplate>(second_type, std::forward<TArgs>(args)...);
|
2018-09-10 17:51:25 +00:00
|
|
|
if (which.idx == TypeIndex::Enum16)
|
2018-12-26 03:32:18 +00:00
|
|
|
return createWithTwoNumericTypesSecond<Int16, AggregateFunctionTemplate>(second_type, std::forward<TArgs>(args)...);
|
2017-12-20 08:14:33 +00:00
|
|
|
return nullptr;
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 15:36:32 +00:00
|
|
|
template <template <typename> class AggregateFunctionTemplate, typename... TArgs>
|
|
|
|
static IAggregateFunction * createWithStringType(const IDataType & argument_type, TArgs && ... args)
|
|
|
|
{
|
|
|
|
WhichDataType which(argument_type);
|
|
|
|
if (which.idx == TypeIndex::String) return new AggregateFunctionTemplate<String>(std::forward<TArgs>(args)...);
|
|
|
|
if (which.idx == TypeIndex::FixedString) return new AggregateFunctionTemplate<String>(std::forward<TArgs>(args)...);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|