Skip to content

Commit f60eb15

Browse files
authored
feat(agg_func): Add QUANTILE_DISC, KURTOSIS, SKEWNESS aggregate functions (#10886)
1 parent 1e93c5b commit f60eb15

File tree

14 files changed

+1370
-31
lines changed

14 files changed

+1370
-31
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: KURTOSIS
3+
---
4+
5+
Aggregate function.
6+
7+
The `KURTOSIS()` function returns the excess kurtosis of all input values.
8+
9+
## Syntax
10+
11+
```sql
12+
KURTOSIS(expression)
13+
```
14+
15+
## Arguments
16+
17+
| Arguments | Description |
18+
| ----------- | ----------- |
19+
| expression | Any numerical expression |
20+
21+
## Return Type
22+
23+
Nullable Float64.
24+
25+
## Examples
26+
27+
```sql
28+
create table aggr(k int, v int, v2 int null);
29+
30+
insert into aggr values
31+
(1, 10, null),
32+
(2, 10, 11),
33+
(2, 10, 15),
34+
(2, 10, 18),
35+
(2, 20, 22),
36+
(2, 20, 25),
37+
(2, 25, null),
38+
(2, 30, 35),
39+
(2, 30, 40),
40+
(2, 30, 50),
41+
(2, 30, 51);
42+
43+
select kurtosis(k), kurtosis(v), kurtosis(v2) from aggr;
44+
+-------------------+---------------------+---------------------+
45+
| kurtosis(k) | kurtosis(v) | kurtosis(v2) |
46+
+-------------------+---------------------+---------------------+
47+
| 10.99999999999836 | -1.9614277138467147 | -1.4451196915855287 |
48+
+-------------------+---------------------+---------------------+
49+
```
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: QUANTILE_CONT
3+
---
4+
5+
Aggregate function.
6+
7+
The QUANTILE_CONT() function computes the interpolated quantile number of a numeric data sequence.
8+
9+
:::caution
10+
NULL values are not counted.
11+
:::
12+
13+
## Syntax
14+
15+
```sql
16+
QUANTILE_CONT(level)(expression)
17+
18+
QUANTILE_CONT(level1, level2, ...)(expression)
19+
```
20+
21+
## Arguments
22+
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 |
28+
29+
## Return Type
30+
31+
Float64 or float64 array based on level number.
32+
33+
## Examples
34+
35+
:::tip
36+
QUANTILE_CONT(0.6)(N) – A table for test with the single `number` column (UInt64) that contains integers from 0 to N-1.
37+
:::
38+
39+
```sql
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+
+---------------------------------------+
55+
```
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
2-
title: QUANTILE
2+
title: QUANTILE_DISC
33
---
44

55
Aggregate function.
66

7-
The QUANTILE_CONT() function computes the interpolated quantile number of a numeric data sequence.
7+
The `QUANTILE_DISC()` function computes the exact quantile number of a numeric data sequence.
8+
The `QUANTILE` alias to `QUANTILE_DISC`
89

910
:::caution
1011
NULL values are not counted.
@@ -13,9 +14,9 @@ NULL values are not counted.
1314
## Syntax
1415

1516
```sql
16-
QUANTILE_CONT(level)(expression)
17+
QUANTILE_DISC(level)(expression)
1718

18-
QUANTILE_CONT(level1, level2, ...)(expression)
19+
QUANTILE_DISC(level1, level2, ...)(expression)
1920
```
2021

2122
## Arguments
@@ -28,28 +29,28 @@ QUANTILE_CONT(level1, level2, ...)(expression)
2829

2930
## Return Type
3031

31-
Float64 or float64 array based on level number.
32+
InputType or array of InputType based on level number.
3233

3334
## Examples
3435

3536
:::tip
36-
QUANTILE_CONT(0.6)(N) – A table for test with the single `number` column (UInt64) that contains integers from 0 to N-1.
37+
QUANTILE_DISC(0.6)(N) – A table for test with the single `number` column (UInt64) that contains integers from 0 to N-1.
3738
:::
3839

3940
```sql
40-
SELECT QUANTILE_CONT(0.6)(number) FROM numbers(10000);
41+
SELECT QUANTILE_DISC(0.6)(number) FROM numbers(10000);
4142
+----------------------------+
42-
| quantile_cont(0.6)(number) |
43+
| QUANTILE_DISC(0.6)(number) |
4344
+----------------------------+
44-
| 5999.4 |
45+
| 5999 |
4546
+----------------------------+
4647
```
4748

4849
```sql
49-
SELECT QUANTILE_CONT(0, 0.5, 0.6, 1)(number) FROM numbers_mt(10000);
50+
SELECT QUANTILE_DISC(0, 0.5, 0.6, 1)(number) FROM numbers_mt(10000);
5051
+---------------------------------------+
51-
| quantile_cont(0, 0.5, 0.6, 1)(number) |
52+
| QUANTILE_DISC(0, 0.5, 0.6, 1)(number) |
5253
+---------------------------------------+
53-
| [0.0,4999.5,5999.4,9999.0] |
54+
| [0, 4999 ,5999 ,9999 ] |
5455
+---------------------------------------+
5556
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: SKEWNESS
3+
---
4+
5+
Aggregate function.
6+
7+
The `SKEWNESS()` function returns the skewness of all input values.
8+
9+
## Syntax
10+
11+
```sql
12+
SKEWNESS(expression)
13+
```
14+
15+
## Arguments
16+
17+
| Arguments | Description |
18+
| ----------- | ----------- |
19+
| expression | Any numerical expression |
20+
21+
## Return Type
22+
23+
Nullable Float64.
24+
25+
## Examples
26+
27+
```sql
28+
create table aggr(k int, v int, v2 int null);
29+
30+
insert into aggr values
31+
(1, 10, null),
32+
(2, 10, 11),
33+
(2, 10, 15),
34+
(2, 10, 18),
35+
(2, 20, 22),
36+
(2, 20, 25),
37+
(2, 25, null),
38+
(2, 30, 35),
39+
(2, 30, 40),
40+
(2, 30, 50),
41+
(2, 30, 51);
42+
43+
select skewness(k), skewness(v), skewness(v2) from aggr;
44+
+--------------------+----------------------+--------------------+
45+
| skewness(k) | skewness(v) | skewness(v2) |
46+
+--------------------+----------------------+--------------------+
47+
| -3.316624790355393 | -0.16344366935199225 | 0.3654008511025841 |
48+
+--------------------+----------------------+--------------------+
49+
```

0 commit comments

Comments
 (0)