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

array_has has inconsistent null handling for scalars and arrays #13682

Open
Kimahriman opened this issue Dec 7, 2024 · 0 comments · May be fixed by #13683
Open

array_has has inconsistent null handling for scalars and arrays #13682

Kimahriman opened this issue Dec 7, 2024 · 0 comments · May be fixed by #13683
Labels
bug Something isn't working

Comments

@Kimahriman
Copy link

Describe the bug

array_has handles nulls differently for scalars and arrays. Scalars return null if all the left hand side values are null, while arrays don't care what values in the left hand side are null. Additionally, other systems like Spark and Postgres have different null behavior, such that if at least one element of the left hand side is null, return null instead of false. I can't find any definitive SQL standard for this, but it might be good to behave consistent with those other systems.

To Reproduce

> create table arrays as values (make_array(1, 2, 3), 4), (make_array(1, 2, NULL), 4), (make_array(NULL, NULL, NULL), 4);
0 row(s) fetched. 
Elapsed 0.017 seconds.

> select array_has(column1, column2) from arrays;
+------------------------------------------+
| array_has(arrays.column1,arrays.column2) |
+------------------------------------------+
| false                                    |
| false                                    |
| false                                    |
+------------------------------------------+
3 row(s) fetched. 
Elapsed 0.007 seconds.

> select array_has([1, 2, 3], 4),
array_has([1, 2, NULL], 4),
array_has([NULL, NULL, NULL], 4);
+------------------------------------------------------------+--------------------------------------------------------+------------------------------------------------+
| array_has(make_array(Int64(1),Int64(2),Int64(3)),Int64(4)) | array_has(make_array(Int64(1),Int64(2),NULL),Int64(4)) | array_has(make_array(NULL,NULL,NULL),Int64(4)) |
+------------------------------------------------------------+--------------------------------------------------------+------------------------------------------------+
| false                                                      | false                                                  |                                                |
+------------------------------------------------------------+--------------------------------------------------------+------------------------------------------------+
1 row(s) fetched. 
Elapsed 0.007 seconds.

Expected behavior

These queries return the same results.

Additional context

No response

@Kimahriman Kimahriman added the bug Something isn't working label Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant