2020-05-14 02:14:50 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionDistinct.h>
|
|
|
|
#include <AggregateFunctions/AggregateFunctionCombinatorFactory.h>
|
2020-06-17 10:02:04 +00:00
|
|
|
#include <AggregateFunctions/Helpers.h>
|
2020-05-14 02:14:50 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
|
|
|
#include "registerAggregateFunctions.h"
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-05-16 00:15:44 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
}
|
2020-05-14 02:14:50 +00:00
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2020-05-16 00:15:44 +00:00
|
|
|
class AggregateFunctionCombinatorDistinct final : public IAggregateFunctionCombinator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
String getName() const override { return "Distinct"; }
|
|
|
|
|
|
|
|
DataTypes transformArguments(const DataTypes & arguments) const override
|
2020-05-14 02:14:50 +00:00
|
|
|
{
|
2020-05-16 00:15:44 +00:00
|
|
|
if (arguments.empty())
|
|
|
|
throw Exception("Incorrect number of arguments for aggregate function with " + getName() + " suffix",
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
2020-05-14 02:14:50 +00:00
|
|
|
|
2020-06-17 10:02:04 +00:00
|
|
|
return arguments;
|
2020-05-16 00:15:44 +00:00
|
|
|
}
|
2020-05-14 02:14:50 +00:00
|
|
|
|
2020-05-16 00:15:44 +00:00
|
|
|
AggregateFunctionPtr transformAggregateFunction(
|
2020-06-17 23:42:40 +00:00
|
|
|
const AggregateFunctionPtr & nested_function,
|
|
|
|
const AggregateFunctionProperties &,
|
|
|
|
const DataTypes & arguments,
|
|
|
|
const Array &) const override
|
2020-05-14 02:14:50 +00:00
|
|
|
{
|
2020-06-17 10:02:04 +00:00
|
|
|
AggregateFunctionPtr res;
|
|
|
|
if (arguments.size() == 1)
|
|
|
|
{
|
2020-06-19 20:13:07 +00:00
|
|
|
res.reset(createWithNumericType<
|
|
|
|
AggregateFunctionDistinct,
|
|
|
|
AggregateFunctionDistinctSingleNumericData>(*arguments[0], nested_function, arguments));
|
|
|
|
|
2020-06-17 10:02:04 +00:00
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
if (arguments[0]->isValueUnambiguouslyRepresentedInContiguousMemoryRegion())
|
2020-06-19 20:13:07 +00:00
|
|
|
return std::make_shared<
|
|
|
|
AggregateFunctionDistinct<
|
|
|
|
AggregateFunctionDistinctSingleGenericData<true>>>(nested_function, arguments);
|
2020-06-17 10:02:04 +00:00
|
|
|
else
|
2020-06-19 20:13:07 +00:00
|
|
|
return std::make_shared<
|
|
|
|
AggregateFunctionDistinct<
|
|
|
|
AggregateFunctionDistinctSingleGenericData<false>>>(nested_function, arguments);
|
2020-06-17 10:02:04 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 20:13:07 +00:00
|
|
|
return std::make_shared<AggregateFunctionDistinct<AggregateFunctionDistinctMultipleGenericData>>(nested_function, arguments);
|
2020-05-14 02:14:50 +00:00
|
|
|
}
|
2020-05-16 00:15:44 +00:00
|
|
|
};
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 00:15:44 +00:00
|
|
|
void registerAggregateFunctionCombinatorDistinct(AggregateFunctionCombinatorFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorDistinct>());
|
|
|
|
}
|
2020-05-14 02:14:50 +00:00
|
|
|
|
|
|
|
}
|