Skip to content
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

CUME_DIST window function returns incorrect results #6827

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments
Closed

CUME_DIST window function returns incorrect results #6827

monetdb-team opened this issue Nov 30, 2020 · 0 comments
Labels
bug Something isn't working normal SQL

Comments

@monetdb-team
Copy link

Date: 2020-02-20 15:48:36 +0100
From: @bernardom29
To: SQL devs <>
Version: 11.35.9 (Nov2019-SP1)
CC: @PedroTadim

Last updated: 2020-02-24 09:32:58 +0100

Comment 27570

Date: 2020-02-20 15:48:36 +0100
From: @bernardom29

The CUME_DIST() window function is returning incorrect results, even returning values above 1 (the return values should always be within 0 and 1).
Overview of CUME_DIST function: https://www.sqlitetutorial.net/sqlite-window-functions/sqlite-cume_dist/

How to reproduce:
1 - Create test table and add some values

create table employees (dep varchar(10), name varchar(20), salary double);
insert into employees values
('mgmt', 'Smith',81),
('dev', 'Jones',55),
('sls', 'Williams',55),
('sls', 'Taylor',62),
('dev', 'Brown',62),
('mgmt', 'Davies',84),
('sls', 'Evans',87),
('sls', 'Wilson',72),
('sls', 'Thomas',72),
('mgmt', 'Johnson',100);

2 - Execute one of these queries, which give incorrect results:

SELECT dep, name, salary, CUME_DIST() OVER (partition by dep ORDER BY salary) cume_dist_val FROM employees;

SELECT dep, name, salary, CUME_DIST() OVER (PARTITION BY dep) cume_dist_val FROM employees;

The expected results would be values between 0 and 1, with each row's value being the number of rows with values lower or equal divided by the total number of rows in the window or partition.
The actual results go above 1 and are incorrect.

Comment 27571

Date: 2020-02-20 16:11:11 +0100
From: MonetDB Mercurial Repository <>

Changeset 176ea6bea667 made by Pedro Ferreira pedro.ferreira@monetdbsolutions.com in the MonetDB repo, refers to this bug.

For complete details, see https//devmonetdborg/hg/MonetDB?cmd=changeset;node=176ea6bea667

Changeset description:

Added test and fix for bug #6827, ie reset accumulator variable after each partition
@monetdb-team monetdb-team added bug Something isn't working normal SQL labels Nov 30, 2020
@sjoerdmullender sjoerdmullender added this to the Ancient Release milestone Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working normal SQL
Projects
None yet
Development

No branches or pull requests

2 participants