-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Implement window functions with partition_by
clause
#558
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
integration-tests/sqls/simple_window_partition_aggregation.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- Licensed to the Apache Software Foundation (ASF) under one | ||
-- or more contributor license agreements. See the NOTICE file | ||
-- distributed with this work for additional information | ||
-- regarding copyright ownership. The ASF licenses this file | ||
-- to you under the Apache License, Version 2.0 (the | ||
-- "License"); you may not use this file except in compliance | ||
-- with the License. You may obtain a copy of the License at | ||
|
||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language gOVERning permissions and | ||
-- limitations under the License. | ||
|
||
SELECT | ||
c9, | ||
row_number() OVER (PARTITION BY c2, c9) AS row_number, | ||
count(c3) OVER (PARTITION BY c2) AS count_c3, | ||
avg(c3) OVER (PARTITION BY c2) AS avg_c3_by_c2, | ||
sum(c3) OVER (PARTITION BY c2) AS sum_c3_by_c2, | ||
max(c3) OVER (PARTITION BY c2) AS max_c3_by_c2, | ||
min(c3) OVER (PARTITION BY c2) AS min_c3_by_c2 | ||
FROM test | ||
ORDER BY c9; |
26 changes: 26 additions & 0 deletions
26
integration-tests/sqls/simple_window_partition_order_aggregation.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- Licensed to the Apache Software Foundation (ASF) under one | ||
-- or more contributor license agreements. See the NOTICE file | ||
-- distributed with this work for additional information | ||
-- regarding copyright ownership. The ASF licenses this file | ||
-- to you under the Apache License, Version 2.0 (the | ||
-- "License"); you may not use this file except in compliance | ||
-- with the License. You may obtain a copy of the License at | ||
|
||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language gOVERning permissions and | ||
-- limitations under the License. | ||
|
||
SELECT | ||
c9, | ||
row_number() OVER (PARTITION BY c2 ORDER BY c9) AS row_number, | ||
count(c3) OVER (PARTITION BY c2 ORDER BY c9) AS count_c3, | ||
avg(c3) OVER (PARTITION BY c2 ORDER BY c9) AS avg_c3_by_c2, | ||
sum(c3) OVER (PARTITION BY c2 ORDER BY c9) AS sum_c3_by_c2, | ||
max(c3) OVER (PARTITION BY c2 ORDER BY c9) AS max_c3_by_c2, | ||
min(c3) OVER (PARTITION BY c2 ORDER BY c9) AS min_c3_by_c2 | ||
FROM test | ||
ORDER BY c9; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 same here applies for normal aggregations as probably happens here: if we have a
partition by
that creates a lot of groups, we will create many individual arrow arrays (which is slow / memory consuming).Probably what would be better in the long run is store the offsets to the values in a contiguous array, and the values as well and extend / update them instead.
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.
Not needed for this PR btw, but just noting there are similar needs/performance issues in both aggregation and window functions.
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.
I agree, not in this pull request but I believe this can warrant a dedicated compute kernel in arrow for batched array slice transformation and then concatenation
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.
@Dandandan down the road I've started to work on this issue:
https://github.com/apache/arrow-datafusion/pull/579/files#diff-8b6b5ea3976c91229244e4e7a31a7026422b1374d1683e44b41af67a6bd43187R246-R254
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.
Yes - that should probably already be quite an improvement 👍