Skip to content

Commit 91cf6f3

Browse files
authored
Merge pull request #10633 from ariesdevil/quantile
feat(aggregate function): quantile_cont supports multiple levels
2 parents 0564a78 + 8b2edb9 commit 91cf6f3

File tree

9 files changed

+234
-243
lines changed

9 files changed

+234
-243
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/doc/15-sql-functions/10-aggregate-functions/aggregate-quantile.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: QUANTILE
44

55
Aggregate function.
66

7-
The QUANTILE() function computes the quantile of a numeric data sequence.
7+
The QUANTILE_CONT() function computes the interpolated quantile number of a numeric data sequence.
88

99
:::caution
1010
NULL values are not counted.
@@ -13,32 +13,43 @@ NULL values are not counted.
1313
## Syntax
1414

1515
```sql
16-
QUANTILE(level)(expression)
16+
QUANTILE_CONT(level)(expression)
17+
18+
QUANTILE_CONT(level1, level2, ...)(expression)
1719
```
1820

1921
## Arguments
2022

21-
| Arguments | Description |
22-
| ----------- |------------------------------------------------------------------------------------------------------------------------------|
23-
| level | level of quantile. Constant floating-point number from 0 to 1. We recommend using a level value in the range of [0.01, 0.99] |
24-
| ----------- | ----------- |
25-
| expression | Any numerical expression |
23+
| Arguments | Description |
24+
|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
25+
| level(s) | level(s) of quantile. Each level is constant floating-point number from 0 to 1. We recommend using a level value in the range of [0.01, 0.99] |
26+
| ----------- | ----------- |
27+
| expression | Any numerical expression |
2628

2729
## Return Type
2830

29-
the type of the value.
31+
Float64 or float64 array based on level number.
3032

3133
## Examples
3234

3335
:::tip
34-
QUANTILE(0.6)(N) – A table for test with the single `number` column (UInt64) that contains integers from 0 to N-1.
36+
QUANTILE_CONT(0.6)(N) – A table for test with the single `number` column (UInt64) that contains integers from 0 to N-1.
3537
:::
3638

3739
```sql
38-
SELECT QUANTILE(0.6)(number) FROM numbers(10000);
39-
+-----------------------+
40-
| quantile(0.6)(number) |
41-
+-----------------------+
42-
| 5999 |
43-
+-----------------------+
40+
SELECT QUANTILE_CONT(0.6)(number) FROM numbers(10000);
41+
+----------------------------+
42+
| quantile_cont(0.6)(number) |
43+
+----------------------------+
44+
| 5999.4 |
45+
+----------------------------+
46+
```
47+
48+
```sql
49+
SELECT QUANTILE_CONT(0, 0.5, 0.6, 1)(number) FROM numbers_mt(10000);
50+
+---------------------------------------+
51+
| quantile_cont(0, 0.5, 0.6, 1)(number) |
52+
+---------------------------------------+
53+
| [0.0,4999.5,5999.4,9999.0] |
54+
+---------------------------------------+
4455
```

src/query/functions/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ h3o = "0.3.0"
3636
hex = "0.4.3"
3737
itertools = "0.10.5"
3838
lexical-core = "0.8.5"
39+
libm = "0.2.6"
3940
match-template = "0.0.1"
4041
md-5 = "0.10.5"
4142
memchr = { version = "2", default-features = false }

0 commit comments

Comments
 (0)