-
Notifications
You must be signed in to change notification settings - Fork 278
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
Quantile serias scalar function #2055
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,4 +22,52 @@ specific language governing permissions and limitations | |||||||||||||||||||||||||||||||||||||||||||||
under the License. | ||||||||||||||||||||||||||||||||||||||||||||||
--> | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
## Description | ||||||||||||||||||||||||||||||||||||||||||||||
The `QUANTILE_PERCENT` function is used to calculate the quantile value for a given percentage. It takes two parameters: a quantile_state column and a constant floating-point number representing the percentage. The function returns a floating-point number that represents the quantile value at the given percentage position. | ||||||||||||||||||||||||||||||||||||||||||||||
## Syntax | ||||||||||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||||||||||
QUANTILE_PERCENT(<quantile_state>, <percent>) | ||||||||||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
## Parameters | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| Parameter | Description | | ||||||||||||||||||||||||||||||||||||||||||||||
| -- | -- | | ||||||||||||||||||||||||||||||||||||||||||||||
| `<quantile_state>` | The target column.| | ||||||||||||||||||||||||||||||||||||||||||||||
| `<percent>` | Target percent.| | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
## Return value | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
A `Double` type to represent quantile. | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
## Example | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
```sql | ||||||||||||||||||||||||||||||||||||||||||||||
CREATE TABLE IF NOT EXISTS ${tableName_21} ( | ||||||||||||||||||||||||||||||||||||||||||||||
`dt` int(11) NULL COMMENT "", | ||||||||||||||||||||||||||||||||||||||||||||||
`id` int(11) NULL COMMENT "", | ||||||||||||||||||||||||||||||||||||||||||||||
`price` quantile_state QUANTILE_UNION NOT NULL COMMENT "" | ||||||||||||||||||||||||||||||||||||||||||||||
) ENGINE=OLAP | ||||||||||||||||||||||||||||||||||||||||||||||
AGGREGATE KEY(`dt`, `id`) | ||||||||||||||||||||||||||||||||||||||||||||||
COMMENT "OLAP" | ||||||||||||||||||||||||||||||||||||||||||||||
DISTRIBUTED BY HASH(`dt`) BUCKETS 1 | ||||||||||||||||||||||||||||||||||||||||||||||
PROPERTIES ("replication_num" = "1"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
INSERT INTO quantile_state_agg_test VALUES(20220201,0, to_quantile_state(1, 2048)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
INSERT INTO quantile_state_agg_test VALUES(20220201,1, to_quantile_state(-1, 2048)), | ||||||||||||||||||||||||||||||||||||||||||||||
(20220201,1, to_quantile_state(0, 2048)),(20220201,1, to_quantile_state(1, 2048)), | ||||||||||||||||||||||||||||||||||||||||||||||
(20220201,1, to_quantile_state(2, 2048)),(20220201,1, to_quantile_state(3, 2048)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
SELECT dt, id, quantile_percent(quantile_union(price), 0) FROM quantile_state_agg_test GROUP BY dt, id ORDER BY dt, id | ||||||||||||||||||||||||||||||||||||||||||||||
-------------- | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
+----------+------+--------------------------------------------+ | ||||||||||||||||||||||||||||||||||||||||||||||
| dt | id | quantile_percent(quantile_union(price), 0) | | ||||||||||||||||||||||||||||||||||||||||||||||
+----------+------+--------------------------------------------+ | ||||||||||||||||||||||||||||||||||||||||||||||
| 20220201 | 0 | 1 | | ||||||||||||||||||||||||||||||||||||||||||||||
| 20220201 | 1 | -1 | | ||||||||||||||||||||||||||||||||||||||||||||||
+----------+------+--------------------------------------------+ | ||||||||||||||||||||||||||||||||||||||||||||||
2 rows in set (0.42 sec) | ||||||||||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+61
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
{ | ||
"title": "quantile_percent", | ||
"title": "quantile_state_empty", | ||
"language": "en" | ||
} | ||
--- | ||
|
@@ -22,4 +22,30 @@ specific language governing permissions and limitations | |
under the License. | ||
--> | ||
|
||
## Description | ||
|
||
Return an empty `quantile_state` type column. | ||
|
||
## Syntax | ||
``` | ||
QUANTILE_STATE_EMPTY() | ||
``` | ||
|
||
## Return value | ||
|
||
An empty `quantile_state` type column. | ||
|
||
## Example | ||
|
||
```sql | ||
-------------- | ||
select quantile_percent(quantile_union(quantile_state_empty()), 0) | ||
-------------- | ||
|
||
+-------------------------------------------------------------+ | ||
| quantile_percent(quantile_union(quantile_state_empty()), 0) | | ||
+-------------------------------------------------------------+ | ||
| NULL | | ||
+-------------------------------------------------------------+ | ||
1 row in set (0.12 sec) | ||
``` | ||
Comment on lines
+40
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 按照 quantile-percent 评论中的统一改一下 example 格式
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
章节之间加上空行,防止渲染错误