From 857bccc9813b02a80bdf319fbe05bd59ac79d8b0 Mon Sep 17 00:00:00 2001 From: Guillaume Tassery Date: Mon, 15 Apr 2019 13:36:24 +0700 Subject: [PATCH 1/7] Add a way to set a size parameter for groupUniqArray --- .../AggregateFunctionGroupUniqArray.cpp | 84 +++++++++++++++---- .../AggregateFunctionGroupUniqArray.h | 29 +++++-- 2 files changed, 86 insertions(+), 27 deletions(-) diff --git a/dbms/src/AggregateFunctions/AggregateFunctionGroupUniqArray.cpp b/dbms/src/AggregateFunctions/AggregateFunctionGroupUniqArray.cpp index 7a99709c33e..13c9b328938 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionGroupUniqArray.cpp +++ b/dbms/src/AggregateFunctions/AggregateFunctionGroupUniqArray.cpp @@ -9,55 +9,103 @@ namespace DB { +namespace ErrorCodes +{ + extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; + extern const int BAD_ARGUMENTS; +} + namespace { /// Substitute return type for Date and DateTime -class AggregateFunctionGroupUniqArrayDate : public AggregateFunctionGroupUniqArray +template +class AggregateFunctionGroupUniqArrayDate : public AggregateFunctionGroupUniqArray { public: - AggregateFunctionGroupUniqArrayDate(const DataTypePtr & argument_type) : AggregateFunctionGroupUniqArray(argument_type) {} + AggregateFunctionGroupUniqArrayDate(const DataTypePtr & argument_type, UInt64 max_elems_ = std::numeric_limits::max()) : AggregateFunctionGroupUniqArray(argument_type, max_elems_) {} DataTypePtr getReturnType() const override { return std::make_shared(std::make_shared()); } }; -class AggregateFunctionGroupUniqArrayDateTime : public AggregateFunctionGroupUniqArray +template +class AggregateFunctionGroupUniqArrayDateTime : public AggregateFunctionGroupUniqArray { public: - AggregateFunctionGroupUniqArrayDateTime(const DataTypePtr & argument_type) : AggregateFunctionGroupUniqArray(argument_type) {} + AggregateFunctionGroupUniqArrayDateTime(const DataTypePtr & argument_type, UInt64 max_elems_ = std::numeric_limits::max()) : AggregateFunctionGroupUniqArray(argument_type, max_elems_) {} DataTypePtr getReturnType() const override { return std::make_shared(std::make_shared()); } }; - -static IAggregateFunction * createWithExtraTypes(const DataTypePtr & argument_type) +template +static IAggregateFunction * createWithExtraTypes(const DataTypePtr & argument_type, TArgs && ... args) { WhichDataType which(argument_type); - if (which.idx == TypeIndex::Date) return new AggregateFunctionGroupUniqArrayDate(argument_type); - else if (which.idx == TypeIndex::DateTime) return new AggregateFunctionGroupUniqArrayDateTime(argument_type); + if (which.idx == TypeIndex::Date) return new AggregateFunctionGroupUniqArrayDate(argument_type, std::forward(args)...); + else if (which.idx == TypeIndex::DateTime) return new AggregateFunctionGroupUniqArrayDateTime(argument_type, std::forward(args)...); else { /// Check that we can use plain version of AggreagteFunctionGroupUniqArrayGeneric if (argument_type->isValueUnambiguouslyRepresentedInContiguousMemoryRegion()) - return new AggreagteFunctionGroupUniqArrayGeneric(argument_type); + return new AggreagteFunctionGroupUniqArrayGeneric(argument_type, std::forward(args)...); else - return new AggreagteFunctionGroupUniqArrayGeneric(argument_type); + return new AggreagteFunctionGroupUniqArrayGeneric(argument_type, std::forward(args)...); } } +template