-
Notifications
You must be signed in to change notification settings - Fork 422
[feature](agg) support aggregation function agg_array_sum #2988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HonestManXin
wants to merge
1
commit into
apache:master
Choose a base branch
from
HonestManXin:agg_array_sum
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
docs/sql-manual/sql-functions/aggregate-functions/agg-array-sum.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| { | ||
| "title": "AGG_ARRAY_SUM", | ||
| "language": "en" | ||
| } | ||
| --- | ||
|
|
||
| ## Description | ||
|
|
||
| Calculate the sum of elements at each position in the input array and return a new array | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```sql | ||
| AGG_ARRAY_SUM(<expr>) | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Description | | ||
| | -- |----------------------------------------------------------------| | ||
| | `<expr>` | Expression to be summed, an Array with element type Numerical. | | ||
|
|
||
| ## Return Value | ||
|
|
||
| Returns a new array containing the sum of elements at each position of the array. | ||
| If there is no valid data within the group, return an empty array. | ||
|
|
||
| ## Example | ||
|
|
||
| ```sql | ||
| -- setup | ||
| CREATE TABLE agg_array_sum_test ( | ||
| `group_id` bigint(20) NOT NULL, | ||
| `array_column` array<bigint(20)> NULL | ||
| ) ENGINE=OLAP | ||
| duplicate KEY(`group_id`) | ||
| DISTRIBUTED BY HASH(`group_id`) BUCKETS 2 | ||
| PROPERTIES ( | ||
| "replication_allocation" = "tag.location.default: 1", | ||
| "in_memory" = "false" | ||
| ); | ||
| insert into agg_array_sum_test values (1,[1,2,3]),(1,[4,5,6]),(2,[10,20]), (2,[40,50,60]), (2, NULL), (3,[30, 50]), (3,[20, null]), (4, null); | ||
| ``` | ||
|
|
||
| ```sql | ||
| select group_id, agg_array_sum(array_column) as sum_array from agg_array_sum_test group by group_id; | ||
| ``` | ||
|
|
||
| ```text | ||
| +----------+--------------+ | ||
| | group_id | sum_array | | ||
| +----------+--------------+ | ||
| | 2 | [50, 70, 60] | | ||
| | 3 | [50, 50] | | ||
| | 1 | [5, 7, 9] | | ||
| | 4 | [] | | ||
| +----------+--------------+ | ||
| ``` | ||
|
|
||
| ```sql | ||
| select agg_array_sum(array_column) as sum_array from agg_array_sum_test where array_column is null; | ||
| ``` | ||
|
|
||
| ```text | ||
| +-----------+ | ||
| | sum_array | | ||
| +-----------+ | ||
| | [] | | ||
| +-----------+ | ||
| ``` | ||
|
|
71 changes: 71 additions & 0 deletions
71
...tent-docs/current/sql-manual/sql-functions/aggregate-functions/agg-array-sum.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| { | ||
| "title": "AGG_ARRAY_SUM", | ||
| "language": "zh-CN" | ||
| } | ||
| --- | ||
|
|
||
| ## 描述 | ||
|
|
||
| 计算输入数组每一位置元素和,返回一个新的数组 | ||
|
|
||
| ## 语法 | ||
|
|
||
| ```sql | ||
| AGG_ARRAY_SUM(<expr>) | ||
| ``` | ||
|
|
||
| ## 参数 | ||
|
|
||
| | 参数 | 说明 | | ||
| | -- |---------------------------------------------| | ||
| | `<expr>` | 需要求和的表达式,元素类型为Numerical的Array。 | | ||
|
|
||
| ## 返回值 | ||
|
|
||
| 返回一个包含数组每个位置元素和的新数组。 | ||
| 如果组内没有合法数据,则返回空数组。 | ||
|
|
||
| ## 举例 | ||
|
|
||
| ```sql | ||
| -- setup | ||
| CREATE TABLE agg_array_sum_test ( | ||
| `group_id` bigint(20) NOT NULL, | ||
| `array_column` array<bigint(20)> NULL | ||
| ) ENGINE=OLAP | ||
| duplicate KEY(`group_id`) | ||
| DISTRIBUTED BY HASH(`group_id`) BUCKETS 2 | ||
| PROPERTIES ( | ||
| "replication_allocation" = "tag.location.default: 1", | ||
| "in_memory" = "false" | ||
| ); | ||
| insert into agg_array_sum_test values (1,[1,2,3]),(1,[4,5,6]),(2,[10,20]), (2,[40,50,60]), (2, NULL), (3,[30, 50]), (3,[20, null]), (4, null); | ||
| ``` | ||
|
|
||
| ```sql | ||
| select group_id, agg_array_sum(array_column) as sum_array from agg_array_sum_test group by group_id; | ||
| ``` | ||
|
|
||
| ```text | ||
| +----------+--------------+ | ||
| | group_id | sum_array | | ||
| +----------+--------------+ | ||
| | 2 | [50, 70, 60] | | ||
| | 3 | [50, 50] | | ||
| | 1 | [5, 7, 9] | | ||
| | 4 | [] | | ||
| +----------+--------------+ | ||
| ``` | ||
|
|
||
| ```sql | ||
| select agg_array_sum(array_column) as sum_array from agg_array_sum_test where array_column is null; | ||
| ``` | ||
|
|
||
| ```text | ||
| +-----------+ | ||
| | sum_array | | ||
| +-----------+ | ||
| | [] | | ||
| +-----------+ | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.