Support '>', '<', '>=', '<=', '<>' in any operator#20830
Conversation
adriangb
left a comment
There was a problem hiding this comment.
This looks great. It's incredible it hasn't been done yet given how straightforward the implementation is!
There was a problem hiding this comment.
Pull request overview
This PR extends DataFusion’s SQL planning for x <op> ANY(array_expr) to support additional comparison operators beyond = (specifically >, <, >=, <=, <>) and adds sqllogictest coverage for the new behavior.
Changes:
- Update SQL-to-relational expression planning to translate
ANYcomparisons into expressions usingarray_min/array_max(andarray_hasfor equality). - Expand
array.sltto validateANYbehavior for>,<,>=,<=, and<>using inline array data.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| datafusion/sql/src/expr/mod.rs | Adds planning support for additional ANY comparison operators by rewriting to array_min/array_max-based predicates. |
| datafusion/sqllogictest/test_files/array.slt | Replaces the prior “unsupported” expectation with new SLT cases validating the added ANY operator support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@buraksenn copilot has some good feedback - could you take a look? |
Indeed, I did not think of NULL cases. Thanks @adriangb. I think last commit addresses these |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
@buraksenn can you please address the comments from Copilot? |
Of course, I was planning to address these late today. I will have time around 6-7 hours later and will finalize this PR |
|
Thank you @buraksenn |
|
Thanks again @buraksenn and @adriangb |
## Which issue does this PR close? - Closes apache#2548. ## Rationale for this change ANY operator only supports equality check ## What changes are included in this PR? Adds support for other expressions and add tests ## Are these changes tested? Added slt tests for this and they all pass ## Are there any user-facing changes? Yes user's can now use any operator with this new expressions
## Which issue does this PR close? - Closes apache#2548. ## Rationale for this change ANY operator only supports equality check ## What changes are included in this PR? Adds support for other expressions and add tests ## Are these changes tested? Added slt tests for this and they all pass ## Are there any user-facing changes? Yes user's can now use any operator with this new expressions
## Which issue does this PR close? - Closes #2547 ## Rationale for this change Related with #20830 all operator does not support operators above. ## What changes are included in this PR? Adds support for other expressions and add tests This is a question actually I've checked behaviors of Postgresql and Duckdb about null semantics and continued with the Postgresql behavior. However, I'm not sure if we want this so also put Duckdb outputs. It would be great to have feedback on this | Query | PostgreSQL | This PR | DuckDB | |---|---|---|---| | `5 = ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 <> ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 > ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 < ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 >= ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 <= ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | ## Are these changes tested? Added slt tests for this and they all pass ## Are there any user-facing changes? Yes user's can now use all operator with this new expressions --------- Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
## Which issue does this PR close? - Closes apache#2547 ## Rationale for this change Related with apache#20830 all operator does not support operators above. ## What changes are included in this PR? Adds support for other expressions and add tests This is a question actually I've checked behaviors of Postgresql and Duckdb about null semantics and continued with the Postgresql behavior. However, I'm not sure if we want this so also put Duckdb outputs. It would be great to have feedback on this | Query | PostgreSQL | This PR | DuckDB | |---|---|---|---| | `5 = ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 <> ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 > ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 < ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 >= ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | | `5 <= ALL(NULL::INT[])` | `NULL` | `NULL` | `true` | ## Are these changes tested? Added slt tests for this and they all pass ## Are there any user-facing changes? Yes user's can now use all operator with this new expressions --------- Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Which issue does this PR close?
Rationale for this change
ANY operator only supports equality check
What changes are included in this PR?
Adds support for other expressions and add tests
Are these changes tested?
Added slt tests for this and they all pass
Are there any user-facing changes?
Yes user's can now use any operator with this new expressions