-
Notifications
You must be signed in to change notification settings - Fork 1.5k
adding support for Min/Max over LargeList and FixedSizeList #16071
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ce3ab71
initial Iteration
logan-keede a789bed
add Sql Logic tests
logan-keede d7447ed
tweak comments
logan-keede f48e37a
Merge branch 'main' into SupportLargeList
logan-keede 4b974c9
unify data, structure tests
logan-keede 20c0ffe
Merge branch 'SupportLargeList' of https://github.com/logan-keede/dat…
logan-keede f10d6af
Merge branch 'main' of https://github.com/apache/datafusion into Supp…
logan-keede 9cd59e9
Deleted by mistake
logan-keede 79b0e88
Merge branch 'main' into SupportLargeList
logan-keede 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,134 @@ | ||
# Min/Max with FixedSizeList over integers | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3, 4), 'FixedSizeList(4, Int64)')), | ||
(arrow_cast(make_array(1, 2), 'FixedSizeList(2, Int64)')); | ||
---- | ||
[1, 2] [1, 2, 3, 4] | ||
|
||
# Min/Max with FixedSizeList over strings | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array('a', 'b', 'c'), 'FixedSizeList(3, Utf8)')), | ||
(arrow_cast(make_array('a', 'b'), 'FixedSizeList(2, Utf8)')); | ||
---- | ||
[a, b] [a, b, c] | ||
|
||
# Min/Max with FixedSizeList over booleans | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(true, false, true), 'FixedSizeList(3, Boolean)')), | ||
(arrow_cast(make_array(true, false), 'FixedSizeList(2, Boolean)')); | ||
---- | ||
[true, false] [true, false, true] | ||
|
||
# Min/Max with FixedSizeList over nullable integers | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(NULL, 1, 2), 'FixedSizeList(3, Int64)')), | ||
(arrow_cast(make_array(1, 2), 'FixedSizeList(2, Int64)')); | ||
---- | ||
[1, 2] [NULL, 1, 2] | ||
|
||
# Min/Max FixedSizeList with different lengths and nulls | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3, 4), 'FixedSizeList(4, Int64)')), | ||
(arrow_cast(make_array(1, 2), 'FixedSizeList(2, Int64)')), | ||
(arrow_cast(make_array(1, NULL, 3), 'FixedSizeList(3, Int64)')); | ||
---- | ||
[1, 2] [1, NULL, 3] | ||
|
||
# Min/Max FixedSizeList with only NULLs | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(NULL, NULL), 'FixedSizeList(2, Int64)')), | ||
(arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)')); | ||
---- | ||
[NULL] [NULL, NULL] | ||
|
||
|
||
# Min/Max FixedSizeList of varying types (integers and NULLs) | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)')), | ||
(arrow_cast(make_array(NULL, 2, 3), 'FixedSizeList(3, Int64)')), | ||
(arrow_cast(make_array(1, 2, NULL), 'FixedSizeList(3, Int64)')); | ||
---- | ||
[1, 2, 3] [NULL, 2, 3] | ||
|
||
# Min/Max FixedSizeList grouped by key with NULLs and differing lengths | ||
query I?? rowsort | ||
SELECT column1, MIN(column2), MAX(column2) FROM VALUES | ||
(0, arrow_cast(make_array(1, NULL, 3), 'FixedSizeList(3, Int64)')), | ||
(0, arrow_cast(make_array(1, 2, 3, 4), 'FixedSizeList(4, Int64)')), | ||
(1, arrow_cast(make_array(1, 2), 'FixedSizeList(2, Int64)')), | ||
(1, arrow_cast(make_array(NULL, 5), 'FixedSizeList(2, Int64)')) | ||
GROUP BY column1; | ||
---- | ||
0 [1, 2, 3, 4] [1, NULL, 3] | ||
1 [1, 2] [NULL, 5] | ||
|
||
# Min/Max FixedSizeList grouped by key with NULLs and differing lengths | ||
query I?? rowsort | ||
SELECT column1, MIN(column2), MAX(column2) FROM VALUES | ||
(0, arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)')), | ||
(0, arrow_cast(make_array(NULL, NULL), 'FixedSizeList(2, Int64)')), | ||
(1, arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)')) | ||
GROUP BY column1; | ||
---- | ||
0 [NULL] [NULL, NULL] | ||
1 [NULL] [NULL] | ||
|
||
# Min/Max grouped FixedSizeList with empty and non-empty | ||
query I?? rowsort | ||
SELECT column1, MIN(column2), MAX(column2) FROM VALUES | ||
(0, arrow_cast(make_array(1), 'FixedSizeList(1, Int64)')), | ||
(1, arrow_cast(make_array(5, 6), 'FixedSizeList(2, Int64)')) | ||
GROUP BY column1; | ||
---- | ||
0 [1] [1] | ||
1 [5, 6] [5, 6] | ||
|
||
# Min/Max over FixedSizeList with a window function | ||
query ? | ||
SELECT min(column1) OVER (ORDER BY column1) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)')), | ||
(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)')), | ||
(arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)')) | ||
---- | ||
[1, 2, 3] | ||
[1, 2, 3] | ||
[1, 2, 3] | ||
|
||
# Min/Max over FixedSizeList with a window function and nulls | ||
query ? | ||
SELECT min(column1) OVER (ORDER BY column1) FROM VALUES | ||
(arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)')), | ||
(arrow_cast(make_array(4, 5), 'FixedSizeList(2, Int64)')), | ||
(arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)')) | ||
---- | ||
[2, 3] | ||
[2, 3] | ||
[2, 3] | ||
|
||
# Min/Max over FixedSizeList with a window function, nulls and ROWS BETWEEN statement | ||
query ? | ||
SELECT min(column1) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM VALUES | ||
(arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)')), | ||
(arrow_cast(make_array(4, 5), 'FixedSizeList(2, Int64)')), | ||
(arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)')) | ||
---- | ||
[2, 3] | ||
[2, 3] | ||
[4, 5] | ||
|
||
# Min/Max over FixedSizeList with a window function using a different column | ||
query ? | ||
SELECT max(column2) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)'), arrow_cast(make_array(4, 5), 'FixedSizeList(2, Int64)')), | ||
(arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)'), arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)')) | ||
---- | ||
[4, 5] | ||
[4, 5] | ||
|
This file contains hidden or 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,148 @@ | ||
# Min/Max with LargeList over integers | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3, 4), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(1, 2), 'LargeList(Int64)')); | ||
---- | ||
[1, 2] [1, 2, 3, 4] | ||
|
||
# Min/Max with LargeList over strings | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array('a', 'b', 'c'), 'LargeList(Utf8)')), | ||
(arrow_cast(make_array('a', 'b'), 'LargeList(Utf8)')); | ||
---- | ||
[a, b] [a, b, c] | ||
|
||
# Min/Max with LargeList over booleans | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(true, false, true), 'LargeList(Boolean)')), | ||
(arrow_cast(make_array(true, false), 'LargeList(Boolean)')); | ||
---- | ||
[true, false] [true, false, true] | ||
|
||
# Min/Max with LargeList over nullable integers | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(NULL, 1, 2), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(1, 2), 'LargeList(Int64)')); | ||
---- | ||
[1, 2] [NULL, 1, 2] | ||
|
||
# Min/Max LargeList with different lengths and nulls | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3, 4), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(1, 2), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(1, NULL, 3), 'LargeList(Int64)')); | ||
---- | ||
[1, 2] [1, NULL, 3] | ||
|
||
# Min/Max LargeList with only NULLs | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(NULL, NULL), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(NULL), 'LargeList(Int64)')); | ||
---- | ||
[NULL] [NULL, NULL] | ||
|
||
# Min/Max LargeList with empty LargeLists | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(1), 'LargeList(Int64)')); | ||
---- | ||
[] [1] | ||
|
||
# Min/Max LargeList of varying types (integers and NULLs) | ||
query ?? | ||
SELECT MIN(column1), MAX(column1) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(NULL, 2, 3), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(1, 2, NULL), 'LargeList(Int64)')); | ||
---- | ||
[1, 2, 3] [NULL, 2, 3] | ||
|
||
# Min/Max LargeList grouped by key with NULLs and differing lengths | ||
query I?? rowsort | ||
SELECT column1, MIN(column2), MAX(column2) FROM VALUES | ||
(0, arrow_cast(make_array(1, NULL, 3), 'LargeList(Int64)')), | ||
(0, arrow_cast(make_array(1, 2, 3, 4), 'LargeList(Int64)')), | ||
(1, arrow_cast(make_array(1, 2), 'LargeList(Int64)')), | ||
(1, arrow_cast(make_array(NULL, 5), 'LargeList(Int64)')), | ||
(1, arrow_cast(make_array(), 'LargeList(Int64)')) | ||
GROUP BY column1; | ||
---- | ||
0 [1, 2, 3, 4] [1, NULL, 3] | ||
1 [] [NULL, 5] | ||
|
||
# Min/Max LargeList grouped by key with NULLs and differing lengths | ||
query I?? rowsort | ||
SELECT column1, MIN(column2), MAX(column2) FROM VALUES | ||
(0, arrow_cast(make_array(NULL), 'LargeList(Int64)')), | ||
(0, arrow_cast(make_array(NULL, NULL), 'LargeList(Int64)')), | ||
(1, arrow_cast(make_array(NULL), 'LargeList(Int64)')) | ||
GROUP BY column1; | ||
---- | ||
0 [NULL] [NULL, NULL] | ||
1 [NULL] [NULL] | ||
|
||
# Min/Max grouped LargeList with empty and non-empty | ||
query I?? rowsort | ||
SELECT column1, MIN(column2), MAX(column2) FROM VALUES | ||
(0, arrow_cast(make_array(), 'LargeList(Int64)')), | ||
(0, arrow_cast(make_array(1), 'LargeList(Int64)')), | ||
(0, arrow_cast(make_array(), 'LargeList(Int64)')), | ||
(1, arrow_cast(make_array(5, 6), 'LargeList(Int64)')), | ||
(1, arrow_cast(make_array(), 'LargeList(Int64)')) | ||
GROUP BY column1; | ||
---- | ||
0 [] [1] | ||
1 [] [5, 6] | ||
|
||
# Min/Max over LargeLists with a window function | ||
query ? | ||
SELECT min(column1) OVER (ORDER BY column1) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(2, 3), 'LargeList(Int64)')) | ||
---- | ||
[1, 2, 3] | ||
[1, 2, 3] | ||
[1, 2, 3] | ||
|
||
# Min/Max over LargeLists with a window function and nulls | ||
query ? | ||
SELECT min(column1) OVER (ORDER BY column1) FROM VALUES | ||
(arrow_cast(make_array(NULL), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(4, 5), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(2, 3), 'LargeList(Int64)')) | ||
---- | ||
[2, 3] | ||
[2, 3] | ||
[2, 3] | ||
|
||
# Min/Max over LargeLists with a window function, nulls and ROWS BETWEEN statement | ||
query ? | ||
SELECT min(column1) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM VALUES | ||
(arrow_cast(make_array(NULL), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(4, 5), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(2, 3), 'LargeList(Int64)')) | ||
---- | ||
[2, 3] | ||
[2, 3] | ||
[4, 5] | ||
|
||
# Min/Max over LargeLists with a window function using a different column | ||
query ? | ||
SELECT max(column2) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM VALUES | ||
(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)'), arrow_cast(make_array(4, 5), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(2, 3), 'LargeList(Int64)'), arrow_cast(make_array(2, 3), 'LargeList(Int64)')), | ||
(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)'), NULL); | ||
---- | ||
[4, 5] | ||
[4, 5] | ||
[2, 3] | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Really nice to get this tested! maybe it's a bit overkill to add dedicated .slt files though. Note that the core logic of the Min/Max function over lists is already tested in
datafusion/datafusion/sqllogictest/test_files/aggregate.slt
Lines 6998 to 7146 in f9326f0
IMO it should be enough to add a small set of basic tests at the end of
aggregate.slt
proving that the newFixedSizeList
andLargeList
types are supported, and rely on the previous vanillaList
tests for checking that the core logic works. Otherwise, it will be unclear if new tests to the Min/Max aggregations over lists logic should also be replicated for all list variants.WDYT? would also be curious to know the stance of other contributors
Uh oh!
There was an error while loading. Please reload this page.
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 did not do anything, Everything was already done!
If you consider that we are actually using a generic logic under the hood then yes, but if we think from the perspective of black-box testing then perhaps it is more prudent to have complete test suite.
(edit:- or we can just leave a note that
code path is currently same, and developer/reviewer should account for that.
)on a side note, I would like to avoid adding any more test to aggregate.slt. see this #13723
it already gives 132 error on my laptop(configuration issues that can be fixed,not an actual problem) but yeah it is a mess to parse through.
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.
👍 that's fair, I wonder if there's a way of having all these tests be executed on
List
,LargeList
andFixedSizeList
types without the need of duplicating them manually. I see that there do is some tooling in place that was used forUtf8
,LargeUtf8
andUtf8View
here #12525. Do you think it's worth a shot?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 guess so. I am currently travelling, I will try to do that tomorrow.