Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
10.3.1-2, 10.3.3-1
Description
The percentile_cont and percentile_disc window functions are available in columnstore and many other databases. These allow calculation of percentiles. Percentile_cont will average 2 rows if one is not identified while Percentile_disc picks the first row in the window. Finally a median function should exist which is equivalent to percentile_cont(0.5).
These have slightly different syntax than other window function to specify the column:
percentile_cont(0.5) within group (order by amount) over (partition by owner) pct_cont,
percentile_disc(0.5) within group (order by amount) over (partition by owner) pct_disc
Some investigation
percentile_cont and percentile_disc are not specifically window functions. They originally are "ordered-set aggregate functions" (#1) which one can also use as window functions (#2):
Ordered-set aggreates
The syntax for case #1:
percentile_cont(fraction) WITHIN GROUP (ORDER BY sort_expression)
|
Note the lack of OVER clause.
Ordered-set aggregate functions are supported by:
- https://www.postgresql.org/docs/current/static/functions-aggregate.html
- http://docs.aws.amazon.com/redshift/latest/dg/c_Aggregate_Functions.html
Neither MariaDB nor MySQL support any "ordered-set aggregate functions".
Ordered-set aggregates as window functions
Syntax for case #2 (ordered-set aggregate, used as window function)
- http://docs.aws.amazon.com/redshift/latest/dg/r_WF_PERCENTILE_DISC.html
- https://docs.oracle.com/cd/B12037_01/server.101/b10759/functions100.htm#i1000909
PERCENTILE_DISC ( percentile )
|
WITHIN GROUP (ORDER BY expr)
|
OVER ( [ PARTITION BY expr_list ] )
|
(BTW: note that PostgreSQL doesn't support ordered-set-aggregates-as-window functions: https://www.postgresql.org/docs/current/static/functions-window.html ,
any built-in or user-defined normal aggregate function (but not ordered-set or hypothetical-set aggregates) can be used as a window function)
Attachments
Issue Links
- blocks
-
MCOL-624 MariaDB 10.2 WF create MEDIAN, PERCENTILE_CONT and PERCENTILE_DISC Window functions
- Closed
- is duplicated by
-
MDEV-4835 Add Median Function
- Closed
- is part of
-
MDEV-12987 complete window function support for columnstore parity
- Open
- relates to
-
MDEV-13854 Supporting datetime fields in the order by clause of Percentile functions
- Open
-
MDEV-27395 Named windows do not work with MEDIAN() window function.
- Open