2011-09-19 03:40:05 +00:00
# include <DB/AggregateFunctions/AggregateFunctionCount.h>
2011-09-25 05:07:47 +00:00
# include <DB/AggregateFunctions/AggregateFunctionSum.h>
2011-09-26 04:00:46 +00:00
# include <DB/AggregateFunctions/AggregateFunctionAvg.h>
2014-08-18 05:45:41 +00:00
# include <DB/AggregateFunctions/AggregateFunctionsMinMaxAny.h>
2013-10-28 14:15:56 +00:00
# include <DB/AggregateFunctions/AggregateFunctionsArgMinMax.h>
2011-09-26 04:00:46 +00:00
# include <DB/AggregateFunctions/AggregateFunctionUniq.h>
2014-07-24 20:20:36 +00:00
# include <DB/AggregateFunctions/AggregateFunctionUniqUpTo.h>
2012-08-26 12:18:50 +00:00
# include <DB/AggregateFunctions/AggregateFunctionGroupArray.h>
2013-07-28 20:53:31 +00:00
# include <DB/AggregateFunctions/AggregateFunctionGroupUniqArray.h>
2013-07-27 19:57:45 +00:00
# include <DB/AggregateFunctions/AggregateFunctionQuantile.h>
# include <DB/AggregateFunctions/AggregateFunctionQuantileTiming.h>
2014-11-21 12:29:33 +00:00
# include <DB/AggregateFunctions/AggregateFunctionQuantileDeterministic.h>
2013-09-11 00:55:31 +00:00
# include <DB/AggregateFunctions/AggregateFunctionIf.h>
2014-03-27 12:48:09 +00:00
# include <DB/AggregateFunctions/AggregateFunctionArray.h>
2014-05-21 13:27:40 +00:00
# include <DB/AggregateFunctions/AggregateFunctionState.h>
# include <DB/AggregateFunctions/AggregateFunctionMerge.h>
2015-03-19 03:58:23 +00:00
# include <DB/AggregateFunctions/AggregateFunctionDebug.h>
2015-04-29 20:31:28 +00:00
# include <DB/AggregateFunctions/AggregateFunctionSequenceMatch.h>
2011-09-19 03:40:05 +00:00
# include <DB/AggregateFunctions/AggregateFunctionFactory.h>
2012-10-29 02:58:52 +00:00
# include <DB/DataTypes/DataTypeDate.h>
# include <DB/DataTypes/DataTypeDateTime.h>
2013-06-25 14:16:16 +00:00
# include <DB/DataTypes/DataTypeString.h>
# include <DB/DataTypes/DataTypeFixedString.h>
2011-09-19 03:40:05 +00:00
namespace DB
{
AggregateFunctionFactory : : AggregateFunctionFactory ( )
{
}
2013-06-25 14:16:16 +00:00
/** Создать агрегатную функцию с числовым типом в параметре шаблона, в зависимости от типа аргумента.
*/
2015-02-27 17:38:21 +00:00
template < template < typename > class AggregateFunctionTemplate >
2013-06-25 14:16:16 +00:00
static IAggregateFunction * createWithNumericType ( const IDataType & argument_type )
{
2014-06-26 00:58:14 +00:00
if ( typeid_cast < const DataTypeUInt8 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt8 > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt16 > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt32 > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt64 > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int8 > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int16 > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int32 > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int64 > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Float32 > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Float64 > ;
2013-06-25 14:16:16 +00:00
else
2014-04-08 07:58:53 +00:00
return nullptr ;
2013-06-25 14:16:16 +00:00
}
2015-02-27 17:38:21 +00:00
template < template < typename , typename > class AggregateFunctionTemplate , class Data >
2013-08-21 13:26:42 +00:00
static IAggregateFunction * createWithNumericType ( const IDataType & argument_type )
{
2014-06-26 00:58:14 +00:00
if ( typeid_cast < const DataTypeUInt8 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt8 , Data > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt16 , Data > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt32 , Data > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt64 , Data > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int8 , Data > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int16 , Data > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int32 , Data > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int64 , Data > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Float32 , Data > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Float64 , Data > ;
2013-08-21 13:26:42 +00:00
else
2014-04-08 07:58:53 +00:00
return nullptr ;
2013-08-21 13:26:42 +00:00
}
2014-08-18 05:45:41 +00:00
2015-02-27 17:38:21 +00:00
template < template < typename , typename > class AggregateFunctionTemplate , template < typename > class Data >
2014-02-02 09:08:06 +00:00
static IAggregateFunction * createWithNumericType ( const IDataType & argument_type )
{
2014-06-26 00:58:14 +00:00
if ( typeid_cast < const DataTypeUInt8 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt8 , Data < UInt8 > > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt16 , Data < UInt16 > > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt32 , Data < UInt32 > > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < UInt64 , Data < UInt64 > > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int8 , Data < Int8 > > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int16 , Data < Int16 > > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int32 , Data < Int32 > > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Int64 , Data < Int64 > > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Float32 , Data < Float32 > > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Float64 , Data < Float64 > > ;
2014-02-02 09:08:06 +00:00
else
2014-04-08 07:58:53 +00:00
return nullptr ;
2014-02-02 09:08:06 +00:00
}
2013-06-25 14:16:16 +00:00
2015-02-27 17:38:21 +00:00
/** Для шаблона с двумя аргументами.
*/
template < typename FirstType , template < typename , typename > class AggregateFunctionTemplate >
static IAggregateFunction * createWithTwoNumericTypesSecond ( const IDataType & second_type )
{
if ( typeid_cast < const DataTypeUInt8 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , UInt8 > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , UInt16 > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , UInt32 > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , UInt64 > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , Int8 > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , Int16 > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , Int32 > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , Int64 > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , Float32 > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & second_type ) ) return new AggregateFunctionTemplate < FirstType , Float64 > ;
else
return nullptr ;
}
template < template < typename , typename > class AggregateFunctionTemplate >
static IAggregateFunction * createWithTwoNumericTypes ( const IDataType & first_type , const IDataType & second_type )
{
if ( typeid_cast < const DataTypeUInt8 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < UInt8 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < UInt16 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < UInt32 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < UInt64 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeInt8 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < Int8 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeInt16 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < Int16 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeInt32 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < Int32 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeInt64 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < Int64 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < Float32 , AggregateFunctionTemplate > ( second_type ) ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & first_type ) ) return createWithTwoNumericTypesSecond < Float64 , AggregateFunctionTemplate > ( second_type ) ;
else
return nullptr ;
}
2014-08-18 05:45:41 +00:00
/// min, max, any, anyLast
2015-02-27 17:38:21 +00:00
template < template < typename > class AggregateFunctionTemplate , template < typename > class Data >
2014-08-18 05:45:41 +00:00
static IAggregateFunction * createAggregateFunctionSingleValue ( const String & name , const DataTypes & argument_types )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
const IDataType & argument_type = * argument_types [ 0 ] ;
if ( typeid_cast < const DataTypeUInt8 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < UInt8 > > > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < UInt16 > > > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < UInt32 > > > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < UInt64 > > > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < Int8 > > > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < Int16 > > > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < Int32 > > > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < Int64 > > > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < Float32 > > > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & argument_type ) ) return new AggregateFunctionTemplate < Data < SingleValueDataFixed < Float64 > > > ;
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) )
return new AggregateFunctionTemplate < Data < SingleValueDataFixed < DataTypeDate : : FieldType > > > ;
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) )
return new AggregateFunctionTemplate < Data < SingleValueDataFixed < DataTypeDateTime : : FieldType > > > ;
else if ( typeid_cast < const DataTypeString * > ( & argument_type ) )
return new AggregateFunctionTemplate < Data < SingleValueDataString > > ;
else
return new AggregateFunctionTemplate < Data < SingleValueDataGeneric > > ;
}
2015-03-01 01:06:49 +00:00
/// argMin, argMax
template < template < typename > class MinMaxData , typename ResData >
static IAggregateFunction * createAggregateFunctionArgMinMaxSecond ( const String & name , const IDataType & val_type )
{
if ( typeid_cast < const DataTypeUInt8 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < UInt8 > > > > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < UInt16 > > > > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < UInt32 > > > > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < UInt64 > > > > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < Int8 > > > > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < Int16 > > > > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < Int32 > > > > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < Int64 > > > > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < Float32 > > > > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < Float64 > > > > ;
else if ( typeid_cast < const DataTypeDate * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < DataTypeDate : : FieldType > > > > ;
else if ( typeid_cast < const DataTypeDateTime * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataFixed < DataTypeDateTime : : FieldType > > > > ;
else if ( typeid_cast < const DataTypeString * > ( & val_type ) )
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataString > > > ;
else
return new AggregateFunctionsArgMinMax < AggregateFunctionsArgMinMaxData < ResData , MinMaxData < SingleValueDataGeneric > > > ;
}
template < template < typename > class MinMaxData >
static IAggregateFunction * createAggregateFunctionArgMinMax ( const String & name , const DataTypes & argument_types )
{
if ( argument_types . size ( ) ! = 2 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
const IDataType & res_type = * argument_types [ 0 ] ;
const IDataType & val_type = * argument_types [ 1 ] ;
if ( typeid_cast < const DataTypeUInt8 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < UInt8 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < UInt16 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < UInt32 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < UInt64 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeInt8 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < Int8 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeInt16 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < Int16 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeInt32 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < Int32 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeInt64 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < Int64 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < Float32 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < Float64 > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeDate * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < DataTypeDate : : FieldType > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeDateTime * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataFixed < DataTypeDateTime : : FieldType > > ( name , val_type ) ;
else if ( typeid_cast < const DataTypeString * > ( & res_type ) )
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataString > ( name , val_type ) ;
else
return createAggregateFunctionArgMinMaxSecond < MinMaxData , SingleValueDataGeneric > ( name , val_type ) ;
}
2013-09-14 22:56:11 +00:00
AggregateFunctionPtr AggregateFunctionFactory : : get ( const String & name , const DataTypes & argument_types , int recursion_level ) const
2011-09-19 03:40:05 +00:00
{
2015-03-19 03:58:23 +00:00
if ( name = = " debug " )
return new AggregateFunctionDebug ;
else if ( name = = " count " )
2011-09-25 05:07:47 +00:00
return new AggregateFunctionCount ;
2011-09-26 04:00:46 +00:00
else if ( name = = " any " )
2014-08-18 05:45:41 +00:00
return createAggregateFunctionSingleValue < AggregateFunctionsSingleValue , AggregateFunctionAnyData > ( name , argument_types ) ;
2011-09-26 04:00:46 +00:00
else if ( name = = " anyLast " )
2014-08-18 05:45:41 +00:00
return createAggregateFunctionSingleValue < AggregateFunctionsSingleValue , AggregateFunctionAnyLastData > ( name , argument_types ) ;
2011-09-26 04:00:46 +00:00
else if ( name = = " min " )
2014-08-18 05:45:41 +00:00
return createAggregateFunctionSingleValue < AggregateFunctionsSingleValue , AggregateFunctionMinData > ( name , argument_types ) ;
2011-09-26 04:00:46 +00:00
else if ( name = = " max " )
2014-08-18 05:45:41 +00:00
return createAggregateFunctionSingleValue < AggregateFunctionsSingleValue , AggregateFunctionMaxData > ( name , argument_types ) ;
2013-10-28 14:15:56 +00:00
else if ( name = = " argMin " )
2015-03-01 01:06:49 +00:00
return createAggregateFunctionArgMinMax < AggregateFunctionMinData > ( name , argument_types ) ;
2013-10-28 14:15:56 +00:00
else if ( name = = " argMax " )
2015-03-01 01:06:49 +00:00
return createAggregateFunctionArgMinMax < AggregateFunctionMaxData > ( name , argument_types ) ;
2012-08-26 12:18:50 +00:00
else if ( name = = " groupArray " )
return new AggregateFunctionGroupArray ;
2013-07-28 20:53:31 +00:00
else if ( name = = " groupUniqArray " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2014-06-26 00:58:14 +00:00
const DataTypeArray * arr = typeid_cast < const DataTypeArray * > ( & * argument_types [ 0 ] ) ;
2013-07-28 20:53:31 +00:00
AggregateFunctionPtr res ;
2014-06-26 00:58:14 +00:00
2013-07-28 20:53:31 +00:00
if ( ! arr )
res = createWithNumericType < AggregateFunctionGroupUniqArray > ( * argument_types [ 0 ] ) ;
else
res = createWithNumericType < AggregateFunctionGroupUniqArrays > ( * arr - > getNestedType ( ) ) ;
2014-06-26 00:58:14 +00:00
2013-07-28 20:53:31 +00:00
if ( ! res )
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
return res ;
}
2011-09-25 05:07:47 +00:00
else if ( name = = " sum " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2013-06-25 14:16:16 +00:00
AggregateFunctionPtr res = createWithNumericType < AggregateFunctionSum > ( * argument_types [ 0 ] ) ;
if ( ! res )
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
return res ;
2011-09-25 05:07:47 +00:00
}
2011-09-26 04:00:46 +00:00
else if ( name = = " avg " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2013-06-25 14:16:16 +00:00
AggregateFunctionPtr res = createWithNumericType < AggregateFunctionAvg > ( * argument_types [ 0 ] ) ;
2011-09-26 04:00:46 +00:00
2013-06-25 14:16:16 +00:00
if ( ! res )
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
return res ;
2011-09-26 04:00:46 +00:00
}
else if ( name = = " uniq " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2013-06-25 14:16:16 +00:00
const IDataType & argument_type = * argument_types [ 0 ] ;
2013-08-21 13:26:42 +00:00
AggregateFunctionPtr res = createWithNumericType < AggregateFunctionUniq , AggregateFunctionUniqUniquesHashSetData > ( * argument_types [ 0 ] ) ;
if ( res )
return res ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) )
2013-08-21 13:26:42 +00:00
return new AggregateFunctionUniq < DataTypeDate : : FieldType , AggregateFunctionUniqUniquesHashSetData > ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) )
2013-08-21 13:26:42 +00:00
return new AggregateFunctionUniq < DataTypeDateTime : : FieldType , AggregateFunctionUniqUniquesHashSetData > ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeString * > ( & argument_type ) | | typeid_cast < const DataTypeFixedString * > ( & argument_type ) )
2013-08-21 13:26:42 +00:00
return new AggregateFunctionUniq < String , AggregateFunctionUniqUniquesHashSetData > ;
else
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
}
else if ( name = = " uniqHLL12 " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
const IDataType & argument_type = * argument_types [ 0 ] ;
AggregateFunctionPtr res = createWithNumericType < AggregateFunctionUniq , AggregateFunctionUniqHLL12Data > ( * argument_types [ 0 ] ) ;
2013-06-25 14:16:16 +00:00
if ( res )
return res ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) )
2015-02-22 07:23:37 +00:00
return new AggregateFunctionUniq < DataTypeDate : : FieldType , AggregateFunctionUniqHLL12Data < DataTypeDate : : FieldType > > ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) )
2015-02-22 07:23:37 +00:00
return new AggregateFunctionUniq < DataTypeDateTime : : FieldType , AggregateFunctionUniqHLL12Data < DataTypeDateTime : : FieldType > > ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeString * > ( & argument_type ) | | typeid_cast < const DataTypeFixedString * > ( & argument_type ) )
2015-02-22 07:23:37 +00:00
return new AggregateFunctionUniq < String , AggregateFunctionUniqHLL12Data < String > > ;
2011-09-26 04:00:46 +00:00
else
2013-06-25 14:16:16 +00:00
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
2011-09-26 04:00:46 +00:00
}
2014-02-02 09:08:06 +00:00
else if ( name = = " uniqExact " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
const IDataType & argument_type = * argument_types [ 0 ] ;
AggregateFunctionPtr res = createWithNumericType < AggregateFunctionUniq , AggregateFunctionUniqExactData > ( * argument_types [ 0 ] ) ;
if ( res )
return res ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) )
2014-02-02 09:08:06 +00:00
return new AggregateFunctionUniq < DataTypeDate : : FieldType , AggregateFunctionUniqExactData < DataTypeDate : : FieldType > > ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) )
2014-02-02 09:08:06 +00:00
return new AggregateFunctionUniq < DataTypeDateTime : : FieldType , AggregateFunctionUniqExactData < DataTypeDateTime : : FieldType > > ;
2014-06-26 00:58:14 +00:00
else if ( typeid_cast < const DataTypeString * > ( & argument_type ) | | typeid_cast < const DataTypeFixedString * > ( & argument_type ) )
2014-02-02 09:08:06 +00:00
return new AggregateFunctionUniq < String , AggregateFunctionUniqExactData < String > > ;
else
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
}
2014-07-24 20:20:36 +00:00
else if ( name = = " uniqUpTo " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
const IDataType & argument_type = * argument_types [ 0 ] ;
AggregateFunctionPtr res = createWithNumericType < AggregateFunctionUniqUpTo > ( * argument_types [ 0 ] ) ;
if ( res )
return res ;
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) )
return new AggregateFunctionUniqUpTo < DataTypeDate : : FieldType > ;
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) )
return new AggregateFunctionUniqUpTo < DataTypeDateTime : : FieldType > ;
else if ( typeid_cast < const DataTypeString * > ( & argument_type ) | | typeid_cast < const DataTypeFixedString * > ( & argument_type ) )
return new AggregateFunctionUniqUpTo < String > ;
else
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
}
2012-10-29 02:58:52 +00:00
else if ( name = = " median " | | name = = " quantile " )
2012-10-23 10:58:53 +00:00
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2014-06-26 00:58:14 +00:00
2013-06-25 14:16:16 +00:00
const IDataType & argument_type = * argument_types [ 0 ] ;
2014-06-26 00:58:14 +00:00
if ( typeid_cast < const DataTypeUInt8 * > ( & argument_type ) ) return new AggregateFunctionQuantile < UInt8 > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & argument_type ) ) return new AggregateFunctionQuantile < UInt16 > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & argument_type ) ) return new AggregateFunctionQuantile < UInt32 > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & argument_type ) ) return new AggregateFunctionQuantile < UInt64 > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & argument_type ) ) return new AggregateFunctionQuantile < Int8 > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & argument_type ) ) return new AggregateFunctionQuantile < Int16 > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & argument_type ) ) return new AggregateFunctionQuantile < Int32 > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & argument_type ) ) return new AggregateFunctionQuantile < Int64 > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & argument_type ) ) return new AggregateFunctionQuantile < Float32 > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & argument_type ) ) return new AggregateFunctionQuantile < Float64 > ;
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) ) return new AggregateFunctionQuantile < DataTypeDate : : FieldType , false > ;
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) ) return new AggregateFunctionQuantile < DataTypeDateTime : : FieldType , false > ;
2012-10-23 10:58:53 +00:00
else
2013-06-25 14:16:16 +00:00
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
2012-10-23 10:58:53 +00:00
}
2013-06-29 23:49:34 +00:00
else if ( name = = " quantiles " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
const IDataType & argument_type = * argument_types [ 0 ] ;
2014-06-26 00:58:14 +00:00
if ( typeid_cast < const DataTypeUInt8 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < UInt8 > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < UInt16 > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < UInt32 > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < UInt64 > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < Int8 > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < Int16 > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < Int32 > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < Int64 > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < Float32 > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & argument_type ) ) return new AggregateFunctionQuantiles < Float64 > ;
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) ) return new AggregateFunctionQuantiles < DataTypeDate : : FieldType , false > ;
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) ) return new AggregateFunctionQuantiles < DataTypeDateTime : : FieldType , false > ;
2013-06-29 23:49:34 +00:00
else
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
}
2013-07-27 19:57:45 +00:00
else if ( name = = " medianTiming " | | name = = " quantileTiming " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
AggregateFunctionPtr res = createWithNumericType < AggregateFunctionQuantileTiming > ( * argument_types [ 0 ] ) ;
if ( ! res )
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
return res ;
}
else if ( name = = " quantilesTiming " )
{
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
AggregateFunctionPtr res = createWithNumericType < AggregateFunctionQuantilesTiming > ( * argument_types [ 0 ] ) ;
if ( ! res )
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
return res ;
}
2015-02-27 17:38:21 +00:00
else if ( name = = " medianTimingWeighted " | | name = = " quantileTimingWeighted " )
{
if ( argument_types . size ( ) ! = 2 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
AggregateFunctionPtr res = createWithTwoNumericTypes < AggregateFunctionQuantileTimingWeighted > ( * argument_types [ 0 ] , * argument_types [ 1 ] ) ;
if ( ! res )
throw Exception ( " Illegal types " + argument_types [ 0 ] - > getName ( ) + " and " + argument_types [ 1 ] - > getName ( )
+ " of arguments for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
return res ;
}
else if ( name = = " quantilesTimingWeighted " )
{
if ( argument_types . size ( ) ! = 2 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
AggregateFunctionPtr res = createWithTwoNumericTypes < AggregateFunctionQuantilesTimingWeighted > ( * argument_types [ 0 ] , * argument_types [ 1 ] ) ;
if ( ! res )
throw Exception ( " Illegal types " + argument_types [ 0 ] - > getName ( ) + " and " + argument_types [ 1 ] - > getName ( )
+ " of arguments for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
return res ;
}
2014-11-21 12:29:33 +00:00
else if ( name = = " quantileDeterministic " )
{
if ( argument_types . size ( ) ! = 2 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2014-11-21 14:07:25 +00:00
const auto determinator_type = argument_types [ 1 ] . get ( ) ;
if ( ! typeid_cast < const DataTypeInt32 * > ( determinator_type ) & &
! typeid_cast < const DataTypeUInt32 * > ( determinator_type ) & &
! typeid_cast < const DataTypeInt64 * > ( determinator_type ) & &
! typeid_cast < const DataTypeUInt64 * > ( determinator_type ) )
{
throw Exception {
" Illegal type " + determinator_type - > getName ( ) + " of second argument for aggregate function " + name +
" , Int32, UInt32, Int64 or UInt64 required " ,
ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT
} ;
}
2014-11-21 12:29:33 +00:00
const IDataType & argument_type = * argument_types [ 0 ] ;
if ( typeid_cast < const DataTypeUInt8 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < UInt8 > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < UInt16 > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < UInt32 > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < UInt64 > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < Int8 > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < Int16 > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < Int32 > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < Int64 > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < Float32 > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < Float64 > ;
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < DataTypeDate : : FieldType , false > ;
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) ) return new AggregateFunctionQuantileDeterministic < DataTypeDateTime : : FieldType , false > ;
else
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
}
else if ( name = = " quantilesDeterministic " )
{
if ( argument_types . size ( ) ! = 2 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2014-11-21 14:07:25 +00:00
const auto determinator_type = argument_types [ 1 ] . get ( ) ;
if ( ! typeid_cast < const DataTypeInt32 * > ( determinator_type ) & &
! typeid_cast < const DataTypeUInt32 * > ( determinator_type ) & &
! typeid_cast < const DataTypeInt64 * > ( determinator_type ) & &
! typeid_cast < const DataTypeUInt64 * > ( determinator_type ) )
{
throw Exception {
" Illegal type " + determinator_type - > getName ( ) + " of second argument for aggregate function " + name +
" , Int32, UInt32, Int64 or UInt64 required " ,
ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT
} ;
}
2014-11-21 12:29:33 +00:00
const IDataType & argument_type = * argument_types [ 0 ] ;
if ( typeid_cast < const DataTypeUInt8 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < UInt8 > ;
else if ( typeid_cast < const DataTypeUInt16 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < UInt16 > ;
else if ( typeid_cast < const DataTypeUInt32 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < UInt32 > ;
else if ( typeid_cast < const DataTypeUInt64 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < UInt64 > ;
else if ( typeid_cast < const DataTypeInt8 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < Int8 > ;
else if ( typeid_cast < const DataTypeInt16 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < Int16 > ;
else if ( typeid_cast < const DataTypeInt32 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < Int32 > ;
else if ( typeid_cast < const DataTypeInt64 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < Int64 > ;
else if ( typeid_cast < const DataTypeFloat32 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < Float32 > ;
else if ( typeid_cast < const DataTypeFloat64 * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < Float64 > ;
else if ( typeid_cast < const DataTypeDate * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < DataTypeDate : : FieldType , false > ;
else if ( typeid_cast < const DataTypeDateTime * > ( & argument_type ) ) return new AggregateFunctionQuantilesDeterministic < DataTypeDateTime : : FieldType , false > ;
else
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
}
2015-04-29 20:31:28 +00:00
else if ( name = = " sequenceMatch " )
{
if ( ! AggregateFunctionSequenceMatch : : sufficientArgs ( argument_types . size ( ) ) )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
return new AggregateFunctionSequenceMatch ;
}
2014-05-21 13:27:40 +00:00
else if ( recursion_level = = 0 & & name . size ( ) > strlen ( " State " ) & & ! ( strcmp ( name . data ( ) + name . size ( ) - strlen ( " State " ) , " State " ) ) )
{
/// Для агрегатных функций вида aggState, где agg - имя другой агрегатной функции.
AggregateFunctionPtr nested = get ( String ( name . data ( ) , name . size ( ) - strlen ( " State " ) ) , argument_types , recursion_level + 1 ) ;
return new AggregateFunctionState ( nested ) ;
}
else if ( recursion_level = = 0 & & name . size ( ) > strlen ( " Merge " ) & & ! ( strcmp ( name . data ( ) + name . size ( ) - strlen ( " Merge " ) , " Merge " ) ) )
{
/// Для агрегатных функций вида aggMerge, где agg - имя другой агрегатной функции.
if ( argument_types . size ( ) ! = 1 )
throw Exception ( " Incorrect number of arguments for aggregate function " + name , ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH ) ;
2014-06-26 00:58:14 +00:00
const DataTypeAggregateFunction * function = typeid_cast < const DataTypeAggregateFunction * > ( & * argument_types [ 0 ] ) ;
2014-05-21 13:27:40 +00:00
if ( ! function )
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
AggregateFunctionPtr nested = get ( String ( name . data ( ) , name . size ( ) - strlen ( " Merge " ) ) , function - > getArgumentsDataTypes ( ) , recursion_level + 1 ) ;
if ( nested - > getName ( ) ! = function - > getFunctionName ( ) )
throw Exception ( " Illegal type " + argument_types [ 0 ] - > getName ( ) + " of argument for aggregate function " + name , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
return new AggregateFunctionMerge ( nested ) ;
}
else if ( recursion_level < = 1 & & name . size ( ) > = 3 & & name [ name . size ( ) - 2 ] = = ' I ' & & name [ name . size ( ) - 1 ] = = ' f ' )
2013-09-11 00:55:31 +00:00
{
2015-02-19 16:27:19 +00:00
if ( argument_types . empty ( ) )
throw Exception {
" Incorrect number of arguments for aggregate function " + name ,
ErrorCodes : : NUMBER_OF_ARGUMENTS_DOESNT_MATCH
} ;
2013-09-14 22:56:11 +00:00
/// Для агрегатных функций вида aggIf, где agg - имя другой агрегатной функции.
2013-10-28 16:13:19 +00:00
DataTypes nested_dt = argument_types ;
nested_dt . pop_back ( ) ;
2014-03-27 12:48:09 +00:00
AggregateFunctionPtr nested = get ( String ( name . data ( ) , name . size ( ) - 2 ) , nested_dt , recursion_level + 1 ) ;
2013-09-11 00:55:31 +00:00
return new AggregateFunctionIf ( nested ) ;
}
2014-05-21 13:27:40 +00:00
else if ( recursion_level < = 2 & & name . size ( ) > strlen ( " Array " ) & & ! ( strcmp ( name . data ( ) + name . size ( ) - strlen ( " Array " ) , " Array " ) ) )
2014-03-27 12:48:09 +00:00
{
/// Для агрегатных функций вида aggArray, где agg - имя другой агрегатной функции.
size_t num_agruments = argument_types . size ( ) ;
DataTypes nested_arguments ;
for ( size_t i = 0 ; i < num_agruments ; + + i )
{
2014-06-26 00:58:14 +00:00
if ( const DataTypeArray * array = typeid_cast < const DataTypeArray * > ( & * argument_types [ i ] ) )
2014-03-27 12:48:09 +00:00
nested_arguments . push_back ( array - > getNestedType ( ) ) ;
else
throw Exception ( " Illegal type " + argument_types [ i ] - > getName ( ) + " of argument # " + toString ( i + 1 ) + " for aggregate function " + name + " . Must be array. " , ErrorCodes : : ILLEGAL_TYPE_OF_ARGUMENT ) ;
}
2014-05-21 13:27:40 +00:00
AggregateFunctionPtr nested = get ( String ( name . data ( ) , name . size ( ) - strlen ( " Array " ) ) , nested_arguments , recursion_level + 2 ) ; /// + 2, чтобы ни один другой модификатор не мог идти перед Array
2014-03-27 12:48:09 +00:00
return new AggregateFunctionArray ( nested ) ;
}
2011-09-25 05:07:47 +00:00
else
throw Exception ( " Unknown aggregate function " + name , ErrorCodes : : UNKNOWN_AGGREGATE_FUNCTION ) ;
}
2011-09-19 03:40:05 +00:00
2011-09-25 05:07:47 +00:00
AggregateFunctionPtr AggregateFunctionFactory : : tryGet ( const String & name , const DataTypes & argument_types ) const
2011-09-19 03:40:05 +00:00
{
2013-05-24 10:49:19 +00:00
return isAggregateFunctionName ( name )
? get ( name , argument_types )
: NULL ;
}
2015-04-24 15:49:30 +00:00
const AggregateFunctionFactory : : FunctionNames & AggregateFunctionFactory : : getFunctionNames ( ) const
2013-05-24 10:49:19 +00:00
{
2015-04-24 15:49:30 +00:00
static FunctionNames names
2013-06-30 10:28:17 +00:00
{
2015-03-19 03:58:23 +00:00
" debug " ,
2013-06-30 10:28:17 +00:00
" count " ,
" any " ,
" anyLast " ,
" min " ,
" max " ,
2013-10-28 14:15:56 +00:00
" argMin " ,
" argMax " ,
2013-06-30 10:28:17 +00:00
" sum " ,
" avg " ,
" uniq " ,
2013-08-21 15:33:45 +00:00
" uniqHLL12 " ,
2014-02-02 09:08:06 +00:00
" uniqExact " ,
2014-07-24 20:20:36 +00:00
" uniqUpTo " ,
2013-06-30 10:28:17 +00:00
" groupArray " ,
2013-07-28 20:53:31 +00:00
" groupUniqArray " ,
2013-06-30 10:28:17 +00:00
" median " ,
" quantile " ,
" quantiles " ,
2013-07-27 19:57:45 +00:00
" medianTiming " ,
" quantileTiming " ,
" quantilesTiming " ,
2015-02-27 17:38:21 +00:00
" quantileTimingWeighted " ,
" quantilesTimingWeighted " ,
" medianTimingWeighted " ,
2014-11-21 12:29:33 +00:00
" quantileDeterministic " ,
2015-04-29 20:31:28 +00:00
" quantilesDeterministic " ,
" sequenceMatch "
2013-06-30 10:28:17 +00:00
} ;
2015-04-24 15:49:30 +00:00
return names ;
}
bool AggregateFunctionFactory : : isAggregateFunctionName ( const String & name , int recursion_level ) const
{
const auto & names = getFunctionNames ( ) ;
if ( std : : find ( names . begin ( ) , names . end ( ) , name ) ! = names . end ( ) )
return true ;
2013-06-30 10:28:17 +00:00
2014-05-21 13:27:40 +00:00
/// Для агрегатных функций вида aggState, где agg - имя другой агрегатной функции.
if ( recursion_level < = 0 & & name . size ( ) > strlen ( " State " ) & & ! ( strcmp ( name . data ( ) + name . size ( ) - strlen ( " State " ) , " State " ) ) )
return isAggregateFunctionName ( String ( name . data ( ) , name . size ( ) - strlen ( " State " ) ) , recursion_level + 1 ) ;
/// Для агрегатных функций вида aggMerge, где agg - имя другой агрегатной функции.
if ( recursion_level < = 0 & & name . size ( ) > strlen ( " Merge " ) & & ! ( strcmp ( name . data ( ) + name . size ( ) - strlen ( " Merge " ) , " Merge " ) ) )
return isAggregateFunctionName ( String ( name . data ( ) , name . size ( ) - strlen ( " Merge " ) ) , recursion_level + 1 ) ;
2013-09-14 22:56:11 +00:00
/// Для агрегатных функций вида aggIf, где agg - имя другой агрегатной функции.
2014-05-21 13:27:40 +00:00
if ( recursion_level < = 1 & & name . size ( ) > = 3 & & name [ name . size ( ) - 2 ] = = ' I ' & & name [ name . size ( ) - 1 ] = = ' f ' )
return isAggregateFunctionName ( String ( name . data ( ) , name . size ( ) - 2 ) , recursion_level + 1 ) ;
2014-03-27 12:48:09 +00:00
/// Для агрегатных функций вида aggArray, где agg - имя другой агрегатной функции.
2014-05-21 13:27:40 +00:00
if ( recursion_level < = 2 & & name . size ( ) > strlen ( " Array " ) & & ! ( strcmp ( name . data ( ) + name . size ( ) - strlen ( " Array " ) , " Array " ) ) )
return isAggregateFunctionName ( String ( name . data ( ) , name . size ( ) - strlen ( " Array " ) ) , recursion_level + 2 ) ; /// + 2, чтобы ни один другой модификатор не мог идти перед Array
2013-09-11 00:55:31 +00:00
2013-06-30 10:28:17 +00:00
return false ;
2011-09-19 03:40:05 +00:00
}
}