-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: New functions and operations for working with arrays #6384
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5680fa7
feat: multidimensional arrays
izveigor 73797ed
feat: array_append, array_prepend, array_concat, array_fill
izveigor 337b4bd
feat: array_dims, array_length
izveigor 787f4c6
feat: array_position, array_positions, array_remove, array_replace, a…
izveigor a667905
feat: trim_array, cardinality
izveigor 7e3f734
feat: docs
izveigor b1346c1
Merge branch 'main' into array_functions
izveigor 586bf9f
refactoring: code cleanup
izveigor 6e438e7
fix: test_scalar_expr
izveigor 312882f
fix: clippy
izveigor 61d41dc
Merge branch 'main' into array_functions
izveigor fd47ee2
Merge branch 'main' into array_functions
izveigor e69a7a1
fix: array_concat capacity
izveigor 8bf120c
fix: cargo fmt
izveigor 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
206 changes: 206 additions & 0 deletions
206
datafusion/core/tests/sqllogictests/test_files/array.slt
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,206 @@ | ||
# 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. | ||
|
||
############# | ||
## Array expressions Tests | ||
############# | ||
|
||
# array scalar function #1 | ||
query ??? rowsort | ||
select make_array(1, 2, 3), make_array(1.0, 2.0, 3.0), make_array('h', 'e', 'l', 'l', 'o'); | ||
---- | ||
[1, 2, 3] [1.0, 2.0, 3.0] [h, e, l, l, o] | ||
|
||
# array scalar function #2 | ||
query ??? rowsort | ||
select make_array(1, 2, 3), make_array(make_array(1, 2), make_array(3, 4)), make_array([[[[1], [2]]]]); | ||
---- | ||
[1, 2, 3] [[1, 2], [3, 4]] [[[[[1], [2]]]]] | ||
|
||
# array scalar function #3 | ||
query ?? rowsort | ||
select make_array([1, 2, 3], [4, 5, 6], [7, 8, 9]), make_array([[1, 2], [3, 4]], [[5, 6], [7, 8]]); | ||
---- | ||
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] | ||
|
||
# array scalar function #4 | ||
query ?? rowsort | ||
select make_array([1.0, 2.0], [3.0, 4.0]), make_array('h', 'e', 'l', 'l', 'o'); | ||
---- | ||
[[1.0, 2.0], [3.0, 4.0]] [h, e, l, l, o] | ||
|
||
# array scalar function #5 | ||
query ? rowsort | ||
select make_array(make_array(make_array(make_array(1, 2, 3), make_array(4, 5, 6)), make_array(make_array(7, 8, 9), make_array(10, 11, 12)))) | ||
---- | ||
[[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]] | ||
|
||
# array_append scalar function | ||
query ??? rowsort | ||
select array_append(make_array(1, 2, 3), 4), array_append(make_array(1.0, 2.0, 3.0), 4.0), array_append(make_array('h', 'e', 'l', 'l'), 'o'); | ||
---- | ||
[1, 2, 3, 4] [1.0, 2.0, 3.0, 4.0] [h, e, l, l, o] | ||
|
||
# array_prepend scalar function | ||
query ??? rowsort | ||
select array_prepend(1, make_array(2, 3, 4)), array_prepend(1.0, make_array(2.0, 3.0, 4.0)), array_prepend('h', make_array('e', 'l', 'l', 'o')); | ||
---- | ||
[1, 2, 3, 4] [1.0, 2.0, 3.0, 4.0] [h, e, l, l, o] | ||
|
||
# array_fill scalar function #1 | ||
query ??? rowsort | ||
select array_fill(11, make_array(1, 2, 3)), array_fill(3, make_array(2, 3)), array_fill(2, make_array(2)); | ||
---- | ||
[[[11, 11, 11], [11, 11, 11]]] [[3, 3, 3], [3, 3, 3]] [2, 2] | ||
|
||
# array_fill scalar function #2 | ||
query ?? rowsort | ||
select array_fill(1, make_array(1, 1, 1)), array_fill(2, make_array(2, 2, 2, 2, 2)); | ||
---- | ||
[[[1]]] [[[[[2, 2], [2, 2]], [[2, 2], [2, 2]]], [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]], [[[[2, 2], [2, 2]], [[2, 2], [2, 2]]], [[[2, 2], [2, 2]], [[2, 2], [2, 2]]]]] | ||
|
||
# array_concat scalar function #1 | ||
query ?? rowsort | ||
select array_concat(make_array(1, 2, 3), make_array(4, 5, 6), make_array(7, 8, 9)), array_concat(make_array([1], [2]), make_array([3], [4])); | ||
---- | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9] [[1], [2], [3], [4]] | ||
|
||
# array_concat scalar function #2 | ||
query ? rowsort | ||
select array_concat(make_array(make_array(1, 2), make_array(3, 4)), make_array(make_array(5, 6), make_array(7, 8))); | ||
---- | ||
[[1, 2], [3, 4], [5, 6], [7, 8]] | ||
|
||
# array_concat scalar function #3 | ||
query ? rowsort | ||
select array_concat(make_array([1], [2], [3]), make_array([4], [5], [6]), make_array([7], [8], [9])); | ||
---- | ||
[[1], [2], [3], [4], [5], [6], [7], [8], [9]] | ||
|
||
# array_concat scalar function #4 | ||
query ? rowsort | ||
select array_concat(make_array([[1]]), make_array([[2]])); | ||
---- | ||
[[[1]], [[2]]] | ||
|
||
# array_position scalar function #1 | ||
query III | ||
select array_position(['h', 'e', 'l', 'l', 'o'], 'l'), array_position([1, 2, 3, 4, 5], 5), array_position([1, 1, 1], 1); | ||
---- | ||
3 5 1 | ||
|
||
# array_position scalar function #2 | ||
query III | ||
select array_position(['h', 'e', 'l', 'l', 'o'], 'l', 4), array_position([1, 2, 5, 4, 5], 5, 4), array_position([1, 1, 1], 1, 2); | ||
---- | ||
4 5 2 | ||
|
||
# array_positions scalar function | ||
query III | ||
select array_positions(['h', 'e', 'l', 'l', 'o'], 'l'), array_positions([1, 2, 3, 4, 5], 5), array_positions([1, 1, 1], 1); | ||
---- | ||
[3, 4] [5] [1, 2, 3] | ||
|
||
# array_replace scalar function | ||
query ??? | ||
select array_replace(make_array(1, 2, 3, 4), 2, 3), array_replace(make_array(1, 4, 4, 5, 4, 6, 7), 4, 0), array_replace(make_array(1, 2, 3), 4, 0); | ||
---- | ||
[1, 3, 3, 4] [1, 0, 0, 5, 0, 6, 7] [1, 2, 3] | ||
|
||
# array_to_string scalar function | ||
query ??? | ||
select array_to_string(['h', 'e', 'l', 'l', 'o'], ','), array_to_string([1, 2, 3, 4, 5], '-'), array_to_string([1.0, 2.0, 3.0], '|'); | ||
---- | ||
h,e,l,l,o 1-2-3-4-5 1|2|3 | ||
|
||
# array_to_string scalar function #2 | ||
query ??? | ||
select array_to_string([1, 1, 1], '1'), array_to_string([[1, 2], [3, 4], [5, 6]], '+'), array_to_string(array_fill(3, [3, 2, 2]), '/\'); | ||
---- | ||
11111 1+2+3+4+5+6 3/\3/\3/\3/\3/\3/\3/\3/\3/\3/\3/\3 | ||
|
||
# cardinality scalar function | ||
query III | ||
select cardinality(make_array(1, 2, 3, 4, 5)), cardinality([1, 3, 5]), cardinality(make_array('h', 'e', 'l', 'l', 'o')); | ||
---- | ||
5 3 5 | ||
|
||
# cardinality scalar function #2 | ||
query II | ||
select cardinality(make_array([1, 2], [3, 4], [5, 6])), cardinality(array_fill(3, array[3, 2, 3])); | ||
---- | ||
6 18 | ||
|
||
# trim_array scalar function | ||
query ??? | ||
select trim_array(make_array(1, 2, 3, 4, 5), 2), trim_array(['h', 'e', 'l', 'l', 'o'], 3), trim_array([1.0, 2.0, 3.0], 2); | ||
---- | ||
[1, 2, 3] [h, e] [1.0] | ||
|
||
# trim_array scalar function #2 | ||
query ?? | ||
select trim_array([[1, 2], [3, 4], [5, 6]], 2), trim_array(array_fill(4, [3, 4, 2]), 2); | ||
---- | ||
[[1, 2]] [[[4, 4], [4, 4], [4, 4], [4, 4]]] | ||
|
||
# array_length scalar function | ||
query III rowsort | ||
select array_length(make_array(1, 2, 3, 4, 5)), array_length(make_array(1, 2, 3)), array_length(make_array([1, 2], [3, 4], [5, 6])); | ||
---- | ||
5 3 3 | ||
|
||
# array_length scalar function #2 | ||
query III rowsort | ||
select array_length(make_array(1, 2, 3, 4, 5), 1), array_length(make_array(1, 2, 3), 1), array_length(make_array([1, 2], [3, 4], [5, 6]), 1); | ||
---- | ||
5 3 3 | ||
|
||
# array_length scalar function #3 | ||
query III rowsort | ||
select array_length(make_array(1, 2, 3, 4, 5), 2), array_length(make_array(1, 2, 3), 2), array_length(make_array([1, 2], [3, 4], [5, 6]), 2); | ||
---- | ||
NULL NULL 2 | ||
|
||
# array_length scalar function #4 | ||
query IIII rowsort | ||
select array_length(array_fill(3, [3, 2, 5]), 1), array_length(array_fill(3, [3, 2, 5]), 2), array_length(array_fill(3, [3, 2, 5]), 3), array_length(array_fill(3, [3, 2, 5]), 4); | ||
---- | ||
3 2 5 NULL | ||
|
||
# array_dims scalar function | ||
query III rowsort | ||
select array_dims(make_array(1, 2, 3)), array_dims(make_array([1, 2], [3, 4])), array_dims(make_array([[[[1], [2]]]])); | ||
---- | ||
[3] [2, 2] [1, 1, 1, 2, 1] | ||
|
||
# array_dims scalar function #2 | ||
query II rowsort | ||
select array_dims(array_fill(2, [1, 2, 3])), array_dims(array_fill(3, [2, 5, 4])); | ||
---- | ||
[1, 2, 3] [2, 5, 4] | ||
|
||
# array_ndims scalar function | ||
query III rowsort | ||
select array_ndims(make_array(1, 2, 3)), array_ndims(make_array([1, 2], [3, 4])), array_ndims(make_array([[[[1], [2]]]])); | ||
---- | ||
1 2 5 | ||
|
||
# array_ndims scalar function #2 | ||
query II rowsort | ||
select array_ndims(array_fill(1, [1, 2, 3])), array_ndims([[[[[[[[[[[[[[[[[[[[[1]]]]]]]]]]]]]]]]]]]]]); | ||
---- | ||
3 21 |
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
Oops, something went wrong.
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.
These are great @izveigor -- thank you so much
the only thing I recommend is adding some additional tests that have
null
in the lists.