-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-6767] PERCENTILE_CONT/PERCENTILE_DISC function are not supported #5095
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
base: main
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 |
|---|---|---|
|
|
@@ -3844,6 +3844,119 @@ select distinct sum(deptno + '1') as deptsum from dept order by 1; | |
|
|
||
| !ok | ||
|
|
||
| # [CALCITE-6767] PERCENTILE_CONT/PERCENTILE_DISC syntax not supported. | ||
| # These sql programs were validated in PostgreSQL | ||
| select | ||
| percentile_cont(0.5) within group (order by empno) as c, | ||
| percentile_disc(0.5) within group (order by empno) as d | ||
| from emp; | ||
| +------+------+ | ||
| | C | D | | ||
| +------+------+ | ||
| | 7785 | 7782 | | ||
| +------+------+ | ||
| (1 row) | ||
|
|
||
| !ok | ||
|
|
||
| # PERCENTILE_CONT / PERCENTILE_DISC with GROUP BY. | ||
|
Contributor
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. Can you please add tests for other numeric types, in particular DOUBLE, some large DECIMALS, some of which are very close to each other, and UNSIGNED?
Member
Author
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. I had added related tests and validate in https://onecompiler.com/oracle/44v8xy4ft The SQL standard may allow Few databases support the UNSIGNED type, so I chose DuckDB for testing; the results returned matched the expected test outcomes.(can be validated in https://shell.duckdb.org/): result is :
Contributor
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. You don't need to run tests on duckdb, these tests would produce the same results using integers. The only thing that is different is the overflow behavior. |
||
| select deptno, | ||
| percentile_cont(0.5) within group (order by empno) as c, | ||
| percentile_disc(0.5) within group (order by empno) as d | ||
| from emp | ||
| group by deptno | ||
| order by deptno; | ||
| +--------+------+------+ | ||
| | DEPTNO | C | D | | ||
| +--------+------+------+ | ||
| | 10 | 7839 | 7839 | | ||
| | 20 | 7788 | 7788 | | ||
| | 30 | 7676 | 7654 | | ||
| +--------+------+------+ | ||
| (3 rows) | ||
|
|
||
| !ok | ||
|
|
||
| # PERCENTILE_CONT / PERCENTILE_DISC honour a descending ORDER BY. | ||
| select | ||
| percentile_disc(0.25) within group (order by empno desc) as d | ||
| from emp; | ||
| +------+ | ||
| | D | | ||
| +------+ | ||
| | 7876 | | ||
| +------+ | ||
| (1 row) | ||
|
|
||
| !ok | ||
|
|
||
| # PERCENTILE_CONT / PERCENTILE_DISC on DOUBLE values. | ||
| select | ||
| percentile_cont(0.5) within group (order by v) as c, | ||
| percentile_disc(0.5) within group (order by v) as d | ||
| from (values (cast(1.5 as double)), | ||
| (cast(2.5 as double)), | ||
| (cast(4.5 as double)), | ||
| (cast(8.5 as double))) as t(v); | ||
| +-----+-----+ | ||
| | C | D | | ||
| +-----+-----+ | ||
| | 3.5 | 2.5 | | ||
| +-----+-----+ | ||
| (1 row) | ||
|
|
||
| !ok | ||
|
|
||
| # PERCENTILE_CONT / PERCENTILE_DISC on large DECIMAL values that are very | ||
| # close together. These 19-digit values exceed the ~15-16 significant digits a | ||
| # double can hold, so the linear interpolation must be done in BigDecimal; | ||
| # converting to double would round 9999999999999999990 to 1.0E19 and lose the | ||
| # trailing digits. | ||
| select | ||
| percentile_cont(0.5) within group (order by v) as c, | ||
| percentile_disc(0.5) within group (order by v) as d | ||
| from (values (cast('9999999999999999990' as decimal(19, 0))), | ||
| (cast('9999999999999999992' as decimal(19, 0)))) as t(v); | ||
| +-----------------------+---------------------+ | ||
| | C | D | | ||
| +-----------------------+---------------------+ | ||
| | 9999999999999999991.0 | 9999999999999999990 | | ||
| +-----------------------+---------------------+ | ||
| (1 row) | ||
|
|
||
| !ok | ||
|
|
||
| # A three-row large DECIMAL group whose 0.75 percentile interpolates between | ||
| # two adjacent, nearly-equal values. | ||
| select | ||
| percentile_cont(0.75) within group (order by v) as c | ||
| from (values (cast('9999999999999999990' as decimal(19, 0))), | ||
| (cast('9999999999999999994' as decimal(19, 0))), | ||
| (cast('9999999999999999998' as decimal(19, 0)))) as t(v); | ||
| +-----------------------+ | ||
| | C | | ||
| +-----------------------+ | ||
| | 9999999999999999996.0 | | ||
| +-----------------------+ | ||
| (1 row) | ||
|
|
||
| !ok | ||
|
|
||
| # PERCENTILE_CONT / PERCENTILE_DISC on UNSIGNED values. | ||
| select | ||
| percentile_cont(0.5) within group (order by v) as c, | ||
| percentile_disc(0.5) within group (order by v) as d | ||
| from (values (cast(10 as int unsigned)), | ||
| (cast(20 as int unsigned))) as t(v); | ||
| +----+----+ | ||
| | C | D | | ||
| +----+----+ | ||
| | 15 | 10 | | ||
| +----+----+ | ||
| (1 row) | ||
|
|
||
| !ok | ||
|
|
||
| # [CALCITE-6839] The SUM function sometimes throws overflow exceptions due | ||
| # to incorrect return types | ||
| !use scott-spark | ||
|
|
||
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.
The result is validated in PostgreSQL in https://onecompiler.com/postgresql/44u4qdgpy and result is as expected