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

[window function] add cume_dist implementation #1076

Merged
merged 1 commit into from
Oct 8, 2021

Conversation

jimexist
Copy link
Member

@jimexist jimexist commented Oct 7, 2021

Which issue does this PR close?

add cume_dist implementation

Related #667

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the datafusion Changes in the datafusion crate label Oct 7, 2021
@jimexist jimexist force-pushed the add-cume-dist branch 2 times, most recently from a716e2a to 6d04995 Compare October 7, 2021 03:02
@jimexist jimexist changed the title add cume_dist implementation [window function] add cume_dist implementation Oct 7, 2021
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jimexist -- looks great to me

I also spot checked some other queries with postgres and datafusion and all looks good:

Postgres:

alamb=# select * from arr;
 x | y
---+----
 1 | 10
 1 | 11
 1 |  3
 1 |  6
 2 | 20
 1 |  3
(6 rows)


alamb=# select x, cume_dist() over (partition by x order by y) from arr;
 x | cume_dist
---+-----------
 1 |       0.4
 1 |       0.4
 1 |       0.6
 1 |       0.8
 1 |         1
 2 |         1
(6 rows)

DataFusion

echo "1,10" > /tmp/arr.csv
echo "1,11" >> /tmp/arr.csv
echo "1,3" >> /tmp/arr.csv
echo "1,6" >> /tmp/arr.csv
echo "2,20" >> /tmp/arr.csv
echo "1,3" >> /tmp/arr.csv
cargo run -p datafusion-cli
> CREATE EXTERNAL TABLE arr(x int, y int)
STORED AS CSV
LOCATION '/tmp/arr.csv';
0 rows in set. Query took 0.000 seconds.
> 
> 
select * from arr;
+---+----+
| x | y  |
+---+----+
| 1 | 10 |
| 1 | 11 |
| 1 | 3  |
| 1 | 6  |
| 2 | 20 |
| 1 | 3  |
+---+----+
6 rows in set. Query took 0.010 seconds.
> select x, cume_dist() over (partition by x order by y) from arr;
+---+-------------+
| x | CUME_DIST() |
+---+-------------+
| 1 | 0.4         |
| 1 | 0.4         |
| 1 | 0.6         |
| 1 | 0.8         |
| 1 | 1           |
| 2 | 1           |
+---+-------------+

) -> Result<ArrayRef> {
let scaler = (partition.end - partition.start) as f64;
let result = Float64Array::from_iter_values(
ranks_in_partition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@alamb alamb merged commit 1eb5d55 into apache:master Oct 8, 2021
@jimexist jimexist deleted the add-cume-dist branch October 8, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants