feat: array functions treat an array as an element#6986
feat: array functions treat an array as an element#6986alamb merged 2 commits intoapache:mainfrom izveigor:list_as_element
Conversation
| [11, 12] | ||
| NULL | ||
|
|
||
| # TODO: Concat columns with different dimensions fails |
There was a problem hiding this comment.
I was able to solve this problem.
cc @jayzhan211
| .collect(); | ||
| let field = Arc::new(Field::new("item", data_type, true)); | ||
|
|
||
| aligned_array = Arc::new(ListArray::try_new( |
There was a problem hiding this comment.
Is there a method how to push NULLs into ListArray::try_new with saving values? 🤔
@tustvold, can you give me some advice if you have free time.
There was a problem hiding this comment.
The last argument to try_new is the Option<NullBuffer> right which defines which elements are nulls.
Perhaps I don't understand your question
| [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]], [[1, 2, 3], [2, 9, 1], [7, 8, 9], [1, 2, 3], [1, 7, 4], [4, 5, 6]], [[7, 8, 9]]] | ||
| [[[11, 12, 13], [14, 15, 16]], [[17, 18, 19], [20, 21, 22]], [[4, 5, 6], [10, 11, 12], [4, 9, 8], [7, 8, 9], [10, 11, 12], [1, 8, 7]], [[10, 11, 12]]] | ||
|
|
||
| # array_concat column-wise #11 (1D + Integers) |
There was a problem hiding this comment.
It seems like the regression, but PostgreSQL does not support concatenation between scalars (integers) and arrays.
Should we keep this feature or is it better to follow the PostgreSQL standard? 🤔
What do you think about it, @jayzhan211?
There was a problem hiding this comment.
I think we don't need to support this.
| [[]] | ||
| [[]] | ||
|
|
||
| # array_concat column-wise #10 (3D + 2D + 1D) |
There was a problem hiding this comment.
When I was writing these examples, I suddenly found a bug: #6992
| # select array_concat(make_array(column3), column4) from arrays_values_v2; | ||
| # array_concat column-wise #9 (2D + 1D) | ||
| query ? | ||
| select array_concat(column4, make_array(column3)) from arrays_values_v2; |
There was a problem hiding this comment.
When I was trying to use make_array with lists, I accidentally found a new bug: #6993
There was a problem hiding this comment.
Does 1D + 2D pass? Do only descending-order dimensions work?
|
Ready for the review, @alamb and @jayzhan211! |
|
Thank you for this PR @izveigor -- I ran out of time today but I have this PR on my list to review tomorrow |
| statement ok | ||
| CREATE TABLE nested_arrays | ||
| AS VALUES | ||
| (make_array(make_array(1, 2, 3), make_array(2, 9, 1), make_array(7, 8, 9), make_array(1, 2, 3), make_array(1, 7, 4), make_array(4, 5, 6)), make_array(7, 8, 9), 2, make_array([[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]])), |
There was a problem hiding this comment.
I recommend adding NULL values -- both as elements as well as the arrays as that is often a corner case that gets overlooked
Perhaps something like
| (make_array(make_array(1, 2, 3), make_array(2, 9, 1), make_array(7, 8, 9), make_array(1, 2, 3), make_array(1, 7, 4), make_array(4, 5, 6)), make_array(7, 8, 9), 2, make_array([[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]])), | |
| (make_array(make_array(1, 2, 3), NULL, make_array(7, 8, 9), make_array(1, 2, 3), make_array(1, 7, 4), make_array(4, 5, 6)), make_array(7, 8, 9), 2, make_array([[NULL, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]])), |
| .collect(); | ||
| let field = Arc::new(Field::new("item", data_type, true)); | ||
|
|
||
| aligned_array = Arc::new(ListArray::try_new( |
There was a problem hiding this comment.
The last argument to try_new is the Option<NullBuffer> right which defines which elements are nulls.
Perhaps I don't understand your question
|
Thanks @izveigor and @jayzhan211 |
Which issue does this PR close?
Closes #6985
Follow on to #6879
Follow on to #6805
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?
Yes