-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: array functions treat an array as an element #6986
Conversation
@@ -554,28 +595,36 @@ select array_concat(column1, column2) from arrays_values_v2; | |||
[11, 12] | |||
NULL | |||
|
|||
# TODO: Concat columns with different dimensions fails |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a method how to push NULL
s 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last argument to try_new
is the Option<NullBuffer>
right which defines which elements are nulls.
Perhaps I don't understand your question
|
||
# array_concat column-wise #11 (1D + Integers) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to support this.
[[]] | ||
[[]] | ||
|
||
# array_concat column-wise #10 (3D + 2D + 1D) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was trying to use make_array
with lists, I accidentally found a new bug: #6993
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.
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 |
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.
LGTM, thanks!
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.
Thank you @izveigor -- the tests are especially nice.
I think adding some coverage of nulls would improve things but this PR is an improvement over master so 👍
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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