Skip to content

Conversation

Jasmine-ge
Copy link
Contributor

Please write user-readable short description of the changes:

Returns an array with the first N items in ascending order.
Syntax:
groupArraySorted(column, N)

Parameters:

  • N – The number of elements to return.
  • column – The value (Integer, String, Float and other Generic types).

Example
Get the first 10 numbers:

SELECT group_array_sorted(number, 10) FROM numbers(100)
┌─group_array_sorted(number, 10)─┐
│  [0,1,2,3,4,5,6,7,8,9]         │
└────────────────────────────────┘

Get all the String implementations of all numbers in column:

SELECT group_array_sorted(str, 5) FROM (SELECT to_string(number) as str FROM numbers(5));
┌─group_array_sorted(str, 5)─┐
│  ['0','1','2','3','4']     │
└────────────────────────────┘

related #901

support group array last

Introduce groupArrayLast() (useful to store last X values) (#44521)

* Cleanup DataTypeCustomSimpleAggregateFunction::checkSupportedFunctions()

Signed-off-by: Azat Khuzhin <[email protected]>

* Remove unused GroupArrayGeneralListImpl

Signed-off-by: Azat Khuzhin <[email protected]>

* Introduce groupArrayLast() (useful to store last X values)

Also do some refactoring to make code cleaner:
- rename insert() to insertWithSampler() (since it is used only for
  groupArraySample())
- split merge methods into Last/RNG/...

Signed-off-by: Azat Khuzhin <[email protected]>

Signed-off-by: Azat Khuzhin <[email protected]>

Bugfix/issue 7122 group array missing arg (#7135) (#7198)
@Jasmine-ge Jasmine-ge requested a review from yl-lisen February 20, 2025 09:05
@Jasmine-ge Jasmine-ge self-assigned this Feb 20, 2025
Fix a crash and a leak in AggregateFunctionGroupArraySorted

std::vector

Fix memory like in groupArraySorted

Fix multiple bugs in groupArraySorted

Fix problem detected by ubsan

Fix groupArraySorted documentation

Revert Revert Add new aggregation function groupArraySorted()

Updated implementation

Fixed style check

Fixed code review issues

Fixed code review issues

Revert Add new aggregation function groupArraySorted()

created groupSortedArray by ..Moving
@Jasmine-ge Jasmine-ge force-pushed the enhancement/issue-901-support-group-array-sorted branch from c9e37c2 to 97a32c4 Compare February 20, 2025 10:07
@yokofly
Copy link
Collaborator

yokofly commented Oct 11, 2025

proton:3.0.1

➜  ~ docker exec -it gen proton-client                                   
proton client version 3.0.1.
Connecting to localhost:8463 as user default.
Connected to proton server version 3.0.1 revision 54473.

proton :) SELECT group_array_sorted(number, 10) FROM numbers(100)

SELECT
  group_array_sorted(number, 10)
FROM
  numbers(100)

Query id: 8f1b08c1-a6f6-4de9-98d5-a5bdd9e94b04

┌─group_array_sorted(number, 10)─┐
│ [0,1,2,3,4,5,6,7,8,9]          │
└────────────────────────────────┘

1 row in set. Elapsed: 0.005 sec. 

proton :) SELECT group_array_sorted(str, 5) FROM (SELECT to_string(number) as str FROM numbers(5));

SELECT
  group_array_sorted(str, 5)
FROM
  (
    SELECT
      to_string(number) AS str
    FROM
      numbers(5)
  )

Query id: 85618ea7-c9b2-4b2a-8196-638157822faa

┌─group_array_sorted(str, 5)─┐
│ ['0','1','2','3','4']      │
└────────────────────────────┘

1 row in set. Elapsed: 0.005 sec. 

proton :) 




@yokofly yokofly closed this Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants