2017-04-01 09:19:00 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionArray.h>
|
2017-12-24 06:50:11 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionCombinatorFactory.h>
|
2018-09-10 17:09:07 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2021-06-07 00:15:11 +00:00
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-05-26 11:32:14 +00:00
|
|
|
struct Settings;
|
2015-09-24 12:40:36 +00:00
|
|
|
|
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 ILLEGAL_TYPE_OF_ARGUMENT;
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2017-12-24 06:50:11 +00:00
|
|
|
class AggregateFunctionCombinatorArray final : public IAggregateFunctionCombinator
|
|
|
|
{
|
|
|
|
public:
|
2018-06-03 20:39:06 +00:00
|
|
|
String getName() const override { return "Array"; }
|
2017-12-24 06:50:11 +00:00
|
|
|
|
|
|
|
DataTypes transformArguments(const DataTypes & arguments) const override
|
|
|
|
{
|
2020-03-09 03:38:43 +00:00
|
|
|
if (arguments.empty())
|
2018-07-23 16:53:22 +00:00
|
|
|
throw Exception("-Array aggregate functions require at least one argument", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
2017-12-24 06:50:11 +00:00
|
|
|
DataTypes nested_arguments;
|
|
|
|
for (const auto & type : arguments)
|
|
|
|
{
|
|
|
|
if (const DataTypeArray * array = typeid_cast<const DataTypeArray *>(type.get()))
|
|
|
|
nested_arguments.push_back(array->getNestedType());
|
|
|
|
else
|
|
|
|
throw Exception("Illegal type " + type->getName() + " of argument"
|
|
|
|
" for aggregate function with " + getName() + " suffix. Must be array.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nested_arguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
AggregateFunctionPtr transformAggregateFunction(
|
2020-06-14 07:44:02 +00:00
|
|
|
const AggregateFunctionPtr & nested_function,
|
|
|
|
const AggregateFunctionProperties &,
|
|
|
|
const DataTypes & arguments,
|
|
|
|
const Array &) const override
|
2017-12-24 06:50:11 +00:00
|
|
|
{
|
|
|
|
return std::make_shared<AggregateFunctionArray>(nested_function, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-24 06:50:11 +00:00
|
|
|
void registerAggregateFunctionCombinatorArray(AggregateFunctionCombinatorFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorArray>());
|
|
|
|
}
|
2017-04-09 12:26:41 +00:00
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|