From 7f553d55ae57a2dcd1dda497736afce1612bdf99 Mon Sep 17 00:00:00 2001 From: Pablo Alegre Date: Fri, 4 Feb 2022 15:53:27 +0100 Subject: [PATCH] fixup! Add groupSortedArray() function - Fix memory access - Support any type as sorting parameter - Fix tests - Rewrite/simplify function addBatchSinglePlace --- .../reference/groupsortedarray.md | 4 +- .../AggregateFunctionGroupSortedArray.cpp | 106 ++++++------ .../AggregateFunctionGroupSortedArray.h | 157 ++++++++++-------- .../AggregateFunctionGroupSortedArrayData.h | 2 +- .../02158_groupsortedarray.reference | 7 +- .../0_stateless/02158_groupsortedarray.sql | 17 +- 6 files changed, 162 insertions(+), 131 deletions(-) diff --git a/docs/en/sql-reference/aggregate-functions/reference/groupsortedarray.md b/docs/en/sql-reference/aggregate-functions/reference/groupsortedarray.md index 06c004173b8..28ad7db3bc6 100644 --- a/docs/en/sql-reference/aggregate-functions/reference/groupsortedarray.md +++ b/docs/en/sql-reference/aggregate-functions/reference/groupsortedarray.md @@ -18,8 +18,8 @@ If the parameter is omitted, default value 10 is used. **Arguments** -- `x` – The value. -- `expr` — Optional. The field or expresion to sort by. If not set values are sorted by themselves. [Integer](../../../sql-reference/data-types/int-uint.md). +- `column` – The value. +- `expr` — Optional. The field or expresion to sort by. If not set values are sorted by themselves. **Example** diff --git a/src/AggregateFunctions/AggregateFunctionGroupSortedArray.cpp b/src/AggregateFunctions/AggregateFunctionGroupSortedArray.cpp index e52091fc597..d47aab2b5be 100644 --- a/src/AggregateFunctions/AggregateFunctionGroupSortedArray.cpp +++ b/src/AggregateFunctions/AggregateFunctionGroupSortedArray.cpp @@ -27,21 +27,22 @@ namespace ErrorCodes namespace { - template - class AggregateFunctionGroupSortedArrayNumeric : public AggregateFunctionGroupSortedArray + template + class AggregateFunctionGroupSortedArrayNumeric : public AggregateFunctionGroupSortedArray { - using AggregateFunctionGroupSortedArray::AggregateFunctionGroupSortedArray; + using AggregateFunctionGroupSortedArray::AggregateFunctionGroupSortedArray; }; - template + template class AggregateFunctionGroupSortedArrayFieldType - : public AggregateFunctionGroupSortedArray + : public AggregateFunctionGroupSortedArray { - using AggregateFunctionGroupSortedArray::AggregateFunctionGroupSortedArray; + using AggregateFunctionGroupSortedArray:: + AggregateFunctionGroupSortedArray; DataTypePtr getReturnType() const override { return std::make_shared(std::make_shared()); } }; - template + template static IAggregateFunction * createWithExtraTypes(const DataTypes & argument_types, UInt64 threshold, const Array & params) { if (argument_types.empty()) @@ -49,45 +50,56 @@ namespace WhichDataType which(argument_types[0]); if (which.idx == TypeIndex::Date) - return new AggregateFunctionGroupSortedArrayFieldType(threshold, argument_types, params); + return new AggregateFunctionGroupSortedArrayFieldType( + threshold, argument_types, params); if (which.idx == TypeIndex::DateTime) - return new AggregateFunctionGroupSortedArrayFieldType(threshold, argument_types, params); + return new AggregateFunctionGroupSortedArrayFieldType( + threshold, argument_types, params); if (argument_types[0]->isValueUnambiguouslyRepresentedInContiguousMemoryRegion()) { - return new AggregateFunctionGroupSortedArray(threshold, argument_types, params); + return new AggregateFunctionGroupSortedArray( + threshold, argument_types, params); } else + { - return new AggregateFunctionGroupSortedArray(threshold, argument_types, params); + return new AggregateFunctionGroupSortedArray( + threshold, argument_types, params); } } - template