2017-04-01 09:19:00 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionMerge.h>
|
2017-12-24 06:50:11 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionCombinatorFactory.h>
|
|
|
|
#include <DataTypes/DataTypeAggregateFunction.h>
|
2017-12-20 07:36:30 +00:00
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-24 06:50:11 +00:00
|
|
|
namespace ErrorCodes
|
2015-09-24 12:40:36 +00:00
|
|
|
{
|
2017-12-24 06:50:11 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
class AggregateFunctionCombinatorMerge final : public IAggregateFunctionCombinator
|
|
|
|
{
|
|
|
|
public:
|
2018-06-03 20:39:06 +00:00
|
|
|
String getName() const override { return "Merge"; }
|
2017-12-24 06:50:11 +00:00
|
|
|
|
|
|
|
DataTypes transformArguments(const DataTypes & arguments) const override
|
|
|
|
{
|
|
|
|
if (arguments.size() != 1)
|
|
|
|
throw Exception("Incorrect number of arguments for aggregate function with " + getName() + " suffix", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
const DataTypePtr & argument = arguments[0];
|
|
|
|
|
|
|
|
const DataTypeAggregateFunction * function = typeid_cast<const DataTypeAggregateFunction *>(argument.get());
|
|
|
|
if (!function)
|
|
|
|
throw Exception("Illegal type " + argument->getName() + " of argument for aggregate function with " + getName() + " suffix"
|
|
|
|
+ " must be AggregateFunction(...)", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
return function->getArgumentsDataTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
AggregateFunctionPtr transformAggregateFunction(
|
|
|
|
const AggregateFunctionPtr & nested_function, const DataTypes & arguments, const Array &) const override
|
|
|
|
{
|
|
|
|
const DataTypePtr & argument = arguments[0];
|
|
|
|
|
|
|
|
const DataTypeAggregateFunction * function = typeid_cast<const DataTypeAggregateFunction *>(argument.get());
|
|
|
|
if (!function)
|
|
|
|
throw Exception("Illegal type " + argument->getName() + " of argument for aggregate function with " + getName() + " suffix"
|
|
|
|
+ " must be AggregateFunction(...)", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
if (nested_function->getName() != function->getFunctionName())
|
|
|
|
throw Exception("Illegal type " + argument->getName() + " of argument for aggregate function with " + getName() + " suffix"
|
|
|
|
+ ", because it corresponds to different aggregate function: " + function->getFunctionName() + " instead of " + nested_function->getName(),
|
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
2019-02-11 19:26:32 +00:00
|
|
|
return std::make_shared<AggregateFunctionMerge>(nested_function, argument);
|
2017-12-24 06:50:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void registerAggregateFunctionCombinatorMerge(AggregateFunctionCombinatorFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorMerge>());
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|