2017-04-01 09:19:00 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionIf.h>
|
2017-12-24 06:50:11 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionCombinatorFactory.h>
|
2019-12-15 06:34:43 +00:00
|
|
|
#include "registerAggregateFunctions.h"
|
2017-12-24 06:50:11 +00:00
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-24 06:50:11 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2020-02-25 18:02:41 +00:00
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
2017-12-24 06:50:11 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
class AggregateFunctionCombinatorIf final : public IAggregateFunctionCombinator
|
|
|
|
{
|
|
|
|
public:
|
2018-06-03 20:39:06 +00:00
|
|
|
String getName() const override { return "If"; }
|
2017-12-24 06:50:11 +00:00
|
|
|
|
|
|
|
DataTypes transformArguments(const DataTypes & arguments) const override
|
|
|
|
{
|
|
|
|
if (arguments.empty())
|
|
|
|
throw Exception("Incorrect number of arguments for aggregate function with " + getName() + " suffix",
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
2018-09-10 17:09:07 +00:00
|
|
|
if (!isUInt8(arguments.back()))
|
2017-12-24 06:50:11 +00:00
|
|
|
throw Exception("Illegal type " + arguments.back()->getName() + " of last argument for aggregate function with " + getName() + " suffix",
|
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
return DataTypes(arguments.begin(), std::prev(arguments.end()));
|
|
|
|
}
|
|
|
|
|
|
|
|
AggregateFunctionPtr transformAggregateFunction(
|
|
|
|
const AggregateFunctionPtr & nested_function, const DataTypes & arguments, const Array &) const override
|
|
|
|
{
|
|
|
|
return std::make_shared<AggregateFunctionIf>(nested_function, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void registerAggregateFunctionCombinatorIf(AggregateFunctionCombinatorFactory & factory)
|
2015-09-24 12:40:36 +00:00
|
|
|
{
|
2017-12-24 06:50:11 +00:00
|
|
|
factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorIf>());
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|