2016-06-07 08:23:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-12-20 08:19:54 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionMinMaxAny.h>
|
2017-07-12 01:16:01 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionArgMinMax.h>
|
2017-12-20 08:19:54 +00:00
|
|
|
#include <AggregateFunctions/FactoryHelpers.h>
|
2017-12-20 21:22:04 +00:00
|
|
|
#include <AggregateFunctions/Helpers.h>
|
2018-09-10 17:09:07 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-12-20 08:19:54 +00:00
|
|
|
|
2016-06-07 08:23:15 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// min, max, any, anyLast
|
2019-05-18 14:15:44 +00:00
|
|
|
template <template <typename, bool> class AggregateFunctionTemplate, template <typename> class Data>
|
2017-12-20 08:19:54 +00:00
|
|
|
static IAggregateFunction * createAggregateFunctionSingleValue(const String & name, const DataTypes & argument_types, const Array & parameters)
|
2016-06-07 08:23:15 +00:00
|
|
|
{
|
2017-12-20 08:19:54 +00:00
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
assertUnary(name, argument_types);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-12-20 20:25:22 +00:00
|
|
|
const DataTypePtr & argument_type = argument_types[0];
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(argument_type);
|
2017-12-20 21:22:04 +00:00
|
|
|
#define DISPATCH(TYPE) \
|
2019-05-18 14:15:44 +00:00
|
|
|
if (which.idx == TypeIndex::TYPE) return new AggregateFunctionTemplate<Data<SingleValueDataFixed<TYPE>>, false>(argument_type);
|
2017-12-20 21:22:04 +00:00
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
|
|
|
#undef DISPATCH
|
|
|
|
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::Date)
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionTemplate<Data<SingleValueDataFixed<DataTypeDate::FieldType>>, false>(argument_type);
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::DateTime)
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionTemplate<Data<SingleValueDataFixed<DataTypeDateTime::FieldType>>, false>(argument_type);
|
2019-12-13 08:31:57 +00:00
|
|
|
if (which.idx == TypeIndex::DateTime64)
|
|
|
|
return new AggregateFunctionTemplate<Data<SingleValueDataFixed<DateTime64>>, false>(argument_type);
|
2019-12-11 14:16:59 +00:00
|
|
|
if (which.idx == TypeIndex::Decimal32)
|
|
|
|
return new AggregateFunctionTemplate<Data<SingleValueDataFixed<Decimal32>>, false>(argument_type);
|
|
|
|
if (which.idx == TypeIndex::Decimal64)
|
|
|
|
return new AggregateFunctionTemplate<Data<SingleValueDataFixed<Decimal64>>, false>(argument_type);
|
|
|
|
if (which.idx == TypeIndex::Decimal128)
|
|
|
|
return new AggregateFunctionTemplate<Data<SingleValueDataFixed<Decimal128>>, false>(argument_type);
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::String)
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionTemplate<Data<SingleValueDataString>, true>(argument_type);
|
2017-12-20 08:39:21 +00:00
|
|
|
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionTemplate<Data<SingleValueDataGeneric>, false>(argument_type);
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// argMin, argMax
|
|
|
|
template <template <typename> class MinMaxData, typename ResData>
|
2017-12-20 20:25:22 +00:00
|
|
|
static IAggregateFunction * createAggregateFunctionArgMinMaxSecond(const DataTypePtr & res_type, const DataTypePtr & val_type)
|
2016-06-07 08:23:15 +00:00
|
|
|
{
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(val_type);
|
2017-12-20 21:22:04 +00:00
|
|
|
#define DISPATCH(TYPE) \
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::TYPE) \
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataFixed<TYPE>>>, false>(res_type, val_type);
|
2017-12-20 21:22:04 +00:00
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
|
|
|
#undef DISPATCH
|
|
|
|
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::Date)
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataFixed<DataTypeDate::FieldType>>>, false>(res_type, val_type);
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::DateTime)
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataFixed<DataTypeDateTime::FieldType>>>, false>(res_type, val_type);
|
2019-12-13 08:31:57 +00:00
|
|
|
if (which.idx == TypeIndex::DateTime64)
|
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataFixed<DateTime64>>>, false>(res_type, val_type);
|
2019-12-11 14:16:59 +00:00
|
|
|
if (which.idx == TypeIndex::Decimal32)
|
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataFixed<Decimal32>>>, false>(res_type, val_type);
|
|
|
|
if (which.idx == TypeIndex::Decimal64)
|
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataFixed<Decimal64>>>, false>(res_type, val_type);
|
|
|
|
if (which.idx == TypeIndex::Decimal128)
|
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataFixed<Decimal128>>>, false>(res_type, val_type);
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::String)
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataString>>, true>(res_type, val_type);
|
2017-12-20 08:19:54 +00:00
|
|
|
|
2019-05-18 14:15:44 +00:00
|
|
|
return new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxData<ResData, MinMaxData<SingleValueDataGeneric>>, false>(res_type, val_type);
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <template <typename> class MinMaxData>
|
2017-12-20 08:19:54 +00:00
|
|
|
static IAggregateFunction * createAggregateFunctionArgMinMax(const String & name, const DataTypes & argument_types, const Array & parameters)
|
2016-06-07 08:23:15 +00:00
|
|
|
{
|
2017-12-20 08:19:54 +00:00
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
assertBinary(name, argument_types);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-12-20 20:25:22 +00:00
|
|
|
const DataTypePtr & res_type = argument_types[0];
|
|
|
|
const DataTypePtr & val_type = argument_types[1];
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2018-09-10 17:09:07 +00:00
|
|
|
WhichDataType which(res_type);
|
2017-12-20 21:22:04 +00:00
|
|
|
#define DISPATCH(TYPE) \
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::TYPE) \
|
2017-12-20 21:22:04 +00:00
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataFixed<TYPE>>(res_type, val_type);
|
|
|
|
FOR_NUMERIC_TYPES(DISPATCH)
|
|
|
|
#undef DISPATCH
|
|
|
|
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::Date)
|
2017-12-20 08:39:21 +00:00
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataFixed<DataTypeDate::FieldType>>(res_type, val_type);
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::DateTime)
|
2017-12-20 08:39:21 +00:00
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataFixed<DataTypeDateTime::FieldType>>(res_type, val_type);
|
2019-12-13 08:31:57 +00:00
|
|
|
if (which.idx == TypeIndex::DateTime64)
|
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataFixed<DateTime64>>(res_type, val_type);
|
2019-12-11 14:16:59 +00:00
|
|
|
if (which.idx == TypeIndex::Decimal32)
|
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataFixed<Decimal32>>(res_type, val_type);
|
|
|
|
if (which.idx == TypeIndex::Decimal64)
|
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataFixed<Decimal64>>(res_type, val_type);
|
|
|
|
if (which.idx == TypeIndex::Decimal128)
|
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataFixed<Decimal128>>(res_type, val_type);
|
2018-09-10 17:09:07 +00:00
|
|
|
if (which.idx == TypeIndex::String)
|
2017-12-20 08:39:21 +00:00
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataString>(res_type, val_type);
|
2017-12-20 08:19:54 +00:00
|
|
|
|
2017-12-20 08:39:21 +00:00
|
|
|
return createAggregateFunctionArgMinMaxSecond<MinMaxData, SingleValueDataGeneric>(res_type, val_type);
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|