Skip to content

feat: support '>', '<', '>=', '<=', '<>' in all operator#21416

Merged
berkaysynnada merged 7 commits intoapache:mainfrom
buraksenn:support-all-operator
Apr 18, 2026
Merged

feat: support '>', '<', '>=', '<=', '<>' in all operator#21416
berkaysynnada merged 7 commits intoapache:mainfrom
buraksenn:support-all-operator

Conversation

@buraksenn
Copy link
Copy Markdown
Contributor

@buraksenn buraksenn commented Apr 6, 2026

Which issue does this PR close?

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

@github-actions github-actions bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Apr 6, 2026
Copy link
Copy Markdown
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

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

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

I agree with following postgres semantics; to me it seems more intuitive and inline with other null operation semantics, and off the top of my head I think DataFusion tries to follow postgres more closely though I may be remembering incorrect (or out of date).

I haven't fully reviewed this PR, since it seems to change both the null semantics for any whilst also introducing all support. It might be a good idea to split these into separate PRs to more them easier to review.

Comment thread datafusion/sql/src/expr/mod.rs Outdated
left_expr: &Expr,
right_expr: &Expr,
compare_op: &BinaryOperator,
is_all: bool,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably more readable to have is_all be an enum instead

// Or some better name
enum QuantifyType {
    All,
    Any,
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll apply this after merging both operators in a follow-up PR. Currently this PR only adds ALL operator support

@buraksenn
Copy link
Copy Markdown
Contributor Author

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

I agree with following postgres semantics; to me it seems more intuitive and inline with other null operation semantics, and off the top of my head I think DataFusion tries to follow postgres more closely though I may be remembering incorrect (or out of date).

I haven't fully reviewed this PR, since it seems to change both the null semantics for any whilst also introducing all support. It might be a good idea to split these into separate PRs to more them easier to review.

Thanks @Jefffrey for checking this PR. I've combined ANY operator logic to not cause duplication but I understand it makes sense to separate PRs. Thus, I've narrowed down PR scope to only include ALL operator support with Postgres null handling and then will open a followup PR for ANY operator

Comment thread datafusion/sql/src/expr/mod.rs Outdated
Comment on lines +117 to +121
# NULL LHS with empty array returns TRUE (vacuous truth)
query B
select NULL = ALL(arrow_cast(make_array(), 'List(Int64)'));
----
true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 null then we'd always return null regardless of the haystack 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Comment on lines +1356 to +1361
when(null_arr_check, null_bool.clone())
.when(empty_check, lit(true))
.when(null_lhs_check, null_bool.clone())
.when(decisive_condition, lit(false))
.when(has_nulls, null_bool)
.otherwise(lit(true))
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

buraksenn and others added 2 commits April 18, 2026 13:09
Comment thread datafusion/sql/src/expr/mod.rs Outdated
Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Copy link
Copy Markdown
Contributor

@berkaysynnada berkaysynnada left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @buraksenn. Looking forward to the follow-ups :)

@berkaysynnada berkaysynnada added this pull request to the merge queue Apr 18, 2026
Merged via the queue into apache:main with commit 1fbbba5 Apr 18, 2026
35 checks passed
@berkaysynnada berkaysynnada deleted the support-all-operator branch April 18, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ALL operator

3 participants