Skip to content
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

fix: array_resize null fix #13209

Merged
merged 4 commits into from
Nov 2, 2024
Merged

Conversation

jonathanc-n
Copy link
Contributor

Which issue does this PR close?

Closes #13200 .

Rationale for this change

What changes are included in this PR?

Added null check for array_resize

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Oct 31, 2024
Comment on lines +141 to +142
// Checks if entire array is null
if array.null_count() == array.len() {
Copy link
Member

@findepi findepi Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array is an array of arrays, right?
what happens if some values are null and some other are not?

For example a query processes some null and non-null arrays.
currently, array_resize converts second array (being null) into an empty array:

> SELECT a, array_resize(a, 1) FROM (VALUES (make_array(1)), (arrow_cast(NULL, 'List(Int32)')), (make_array(3))) t(a);
+-----+----------------------------+
| a   | array_resize(t.a,Int64(1)) |
+-----+----------------------------+
| [1] | [1]                        |
|     | []                         |           <!-------- should be NULL
| [3] | [3]                        |
+-----+----------------------------+

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out, I overlooked that.

@@ -7013,6 +7013,12 @@ select array_resize(arrow_cast([[1], [2], [3]], 'LargeList(List(Int64))'), 10, [
----
[[1], [2], [3], [5], [5], [5], [5], [5], [5], [5]]

# array_resize null value
query ?
select array_resize(arrow_cast(NULL, 'List(Int8)'), 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add columnar test?

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jonathanc-n
Copy link
Contributor Author

I kept two null checks in the array_resize function: one in the array_resize_inner function and one in the general_list_resize function. The first null check is needed for the original problem of handling cases like SELECT array_resize(arrow_cast(NULL, 'List(Int8)'), 1);. This scenario can't be checked by the second null check because the array has a length of zero. With a length of zero, it conflicts with the null builder, as the null counts as a length of one, which isn't the expected value when constructing the result. This is due to the null array and the data array needing to have matching lengths.

@jayzhan211

This comment was marked as outdated.

@jatin510
Copy link
Contributor

jatin510 commented Nov 1, 2024

lgtm @alamb

@jayzhan211 jayzhan211 merged commit 24d953e into apache:main Nov 2, 2024
24 checks passed
@jayzhan211
Copy link
Contributor

Thanks @jonathanc-n @findepi @jatin510

@jonathanc-n jonathanc-n deleted the array_resize-null-fix branch November 17, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

null value causes panic in array_resize
4 participants