-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: support '>', '<', '>=', '<=', '<>' in all operator #21416
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
Changes from all commits
5b400e2
d106a0d
57c54d9
7051f1b
78de7a4
722aad8
db93e37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| # 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. | ||
|
|
||
| ## all operator | ||
|
|
||
| # = ALL: true when all elements equal val | ||
| query B | ||
| select 5 = ALL(make_array(5, 5, 5)); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 5 = ALL(make_array(5, 5, 3)); | ||
| ---- | ||
| false | ||
|
|
||
| # <> ALL: true when val differs from every element | ||
| query B | ||
| select 5 <> ALL(make_array(1, 2, 3)); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 5 <> ALL(make_array(1, 2, 5)); | ||
| ---- | ||
| false | ||
|
|
||
| # > ALL: true when val greater than all elements | ||
| query B | ||
| select 10 > ALL(make_array(1, 2, 3)); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 3 > ALL(make_array(1, 2, 3)); | ||
| ---- | ||
| false | ||
|
|
||
| # < ALL: true when val less than all elements | ||
| query B | ||
| select 0 < ALL(make_array(1, 2, 3)); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 2 < ALL(make_array(1, 2, 3)); | ||
| ---- | ||
| false | ||
|
|
||
| # >= ALL: true when val >= all elements | ||
| query B | ||
| select 5 >= ALL(make_array(1, 2, 5)); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 4 >= ALL(make_array(1, 2, 5)); | ||
| ---- | ||
| false | ||
|
|
||
| # <= ALL: true when val <= all elements | ||
| query B | ||
| select 1 <= ALL(make_array(1, 2, 5)); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 2 <= ALL(make_array(1, 2, 5)); | ||
| ---- | ||
| false | ||
|
|
||
| # Empty arrays: all operators return TRUE (vacuous truth) | ||
| query B | ||
| select 5 = ALL(arrow_cast(make_array(), 'List(Int64)')); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 5 <> ALL(arrow_cast(make_array(), 'List(Int64)')); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 5 > ALL(arrow_cast(make_array(), 'List(Int64)')); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 5 < ALL(arrow_cast(make_array(), 'List(Int64)')); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 5 >= ALL(arrow_cast(make_array(), 'List(Int64)')); | ||
| ---- | ||
| true | ||
|
|
||
| query B | ||
| select 5 <= ALL(arrow_cast(make_array(), 'List(Int64)')); | ||
| ---- | ||
| true | ||
|
|
||
| # NULL LHS with empty array returns TRUE (vacuous truth) | ||
| query B | ||
| select NULL = ALL(arrow_cast(make_array(), 'List(Int64)')); | ||
| ---- | ||
| true | ||
|
Comment on lines
+117
to
+121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this a bit surprising since I would assume if the needle is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was surprised about the semantics and results as well btw. That's why I've checked every edge case with postgres and continued with their approach but you're right |
||
|
|
||
| # NULL LHS with non-empty array returns NULL | ||
| query B | ||
| select NULL = ALL(make_array(1, 2, 3)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select NULL > ALL(make_array(1, 2, 3)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select NULL <> ALL(make_array(1, 2, 3)); | ||
| ---- | ||
| NULL | ||
|
|
||
| # All-NULL arrays: returns NULL | ||
| query B | ||
| select 5 = ALL(make_array(NULL::INT, NULL::INT)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 5 <> ALL(make_array(NULL::INT, NULL::INT)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 5 > ALL(make_array(NULL::INT, NULL::INT)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 5 < ALL(make_array(NULL::INT, NULL::INT)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 5 >= ALL(make_array(NULL::INT, NULL::INT)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 5 <= ALL(make_array(NULL::INT, NULL::INT)); | ||
| ---- | ||
| NULL | ||
|
|
||
| # Mixed NULL + non-NULL (non-NULL elements satisfy, but NULLs present → NULL) | ||
| query B | ||
| select 5 > ALL(make_array(3, NULL)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 5 >= ALL(make_array(5, NULL)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 1 < ALL(make_array(3, NULL)); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 1 <= ALL(make_array(1, NULL)); | ||
| ---- | ||
| NULL | ||
|
|
||
| # Mixed NULL + non-NULL (not satisfying condition → FALSE wins over NULL) | ||
| query B | ||
| select 5 > ALL(make_array(6, NULL)); | ||
| ---- | ||
| false | ||
|
|
||
| query B | ||
| select 5 < ALL(make_array(3, NULL)); | ||
| ---- | ||
| false | ||
|
|
||
| query B | ||
| select 5 = ALL(make_array(5, 3, NULL)); | ||
| ---- | ||
| false | ||
|
|
||
| # NULL array input returns NULL | ||
| query B | ||
| select 5 = ALL(NULL::INT[]); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 5 > ALL(NULL::INT[]); | ||
| ---- | ||
| NULL | ||
|
|
||
| query B | ||
| select 5 < ALL(NULL::INT[]); | ||
| ---- | ||
| NULL | ||
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 do wonder if we're better off having a UDF implementation instead of this case approach, though maybe thats something that can be explored as a followup
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 thinking of this as well especially regarding performance wise. As you've said I thought maybe I can have a followup UDF implementation and compare results