You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Jefffrey (via GitHub)" <gi...@apache.org> on 2026/06/16 05:48:46 UTC
[PR] Add `plan_any`/`plan_all` to `ExprPlanner` to decouple functions from sql crate [datafusion]
Jefffrey opened a new pull request, #22967:
URL: https://github.com/apache/datafusion/pull/22967
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- N/A
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
sql crate toml states that it should not depend on the functions crates:
https://github.com/apache/datafusion/blob/127731b11487e24fa1291b94d5d97b0e9b58592b/datafusion/sql/Cargo.toml#L49-L59
However on line 59 it is still depending on the nested functions crate, due to any/all planning support:
https://github.com/apache/datafusion/blob/127731b11487e24fa1291b94d5d97b0e9b58592b/datafusion/sql/src/expr/mod.rs#L1263-L1272
- Since needs access to `array_has` function. Aim to decouple these crates via using `ExprPlanner` trait.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `plan_any`/`plan_all` to `ExprPlanner` to decouple functions from sql crate [datafusion]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #22967:
URL: https://github.com/apache/datafusion/pull/22967#issuecomment-5087928271
## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/22967?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `93.84615%` with `4 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 80.66%. Comparing base ([`e8a65f2`](https://app.codecov.io/gh/apache/datafusion/commit/e8a65f2d6f24afa75192fc63aca38011ede88800?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`3b74539`](https://app.codecov.io/gh/apache/datafusion/commit/3b7453922afaea7979dc4ff2295cfa0e27e2288f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/22967?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [datafusion/functions-nested/src/planner.rs](https://app.codecov.io/gh/apache/datafusion/pull/22967?src=pr&el=tree&filepath=datafusion%2Ffunctions-nested%2Fsrc%2Fplanner.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9mdW5jdGlvbnMtbmVzdGVkL3NyYy9wbGFubmVyLnJz) | 93.22% | [3 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/22967?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #22967 +/- ##
==========================================
- Coverage 80.66% 80.66% -0.01%
==========================================
Files 1095 1095
Lines 372294 372303 +9
Branches 372294 372303 +9
==========================================
- Hits 300324 300314 -10
- Misses 54055 54069 +14
- Partials 17915 17920 +5
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/22967?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `plan_any`/`plan_all` to `ExprPlanner` to decouple functions from sql crate [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #22967:
URL: https://github.com/apache/datafusion/pull/22967#discussion_r3418427514
##########
datafusion/sql/Cargo.toml:
##########
@@ -56,7 +56,6 @@ bigdecimal = { workspace = true }
chrono = { workspace = true }
datafusion-common = { workspace = true, features = ["sql"] }
datafusion-expr = { workspace = true, features = ["sql"] }
-datafusion-functions-nested = { workspace = true, features = ["sql"] }
Review Comment:
main benefit here
##########
datafusion/functions-nested/src/planner.rs:
##########
@@ -120,6 +124,119 @@ impl ExprPlanner for NestedFunctionPlanner {
ScalarFunction::new_udf(map_udf(), vec![keys, values]),
)))
}
+
+ fn plan_any(&self, args: RawAnyAllExpr) -> Result<PlannerResult<RawAnyAllExpr>> {
Review Comment:
this implementation code is copied essentially verbatim from `sql/src/expr/mod.rs`; the only modifications being some renaming of variables (for `any` it called them left/right which are now aligned to needle/haystack) and some plumbing to make it work with the signatures of `plan_any`/`plan_all`
##########
datafusion/sql/src/expr/mod.rs:
##########
@@ -615,9 +613,24 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
planner_context,
),
_ => {
- let left_expr = self.sql_to_expr(*left, schema, planner_context)?;
- let right_expr = self.sql_to_expr(*right, schema, planner_context)?;
- plan_any_op(left_expr, right_expr, &compare_op)
+ let needle = self.sql_to_expr(*left, schema, planner_context)?;
+ let haystack = self.sql_to_expr(*right, schema, planner_context)?;
Review Comment:
one part i'm not sure about was whether to include this subquery case as part of this `plan_any`/`plan_all` call; maybe its better to just name these as `plan_any_nested`/`plan_all_nested` to differentiate it from the subquery planning, which we'll keep in `datafusion-sql`?
##########
datafusion/functions-nested/src/planner.rs:
##########
@@ -120,6 +124,119 @@ impl ExprPlanner for NestedFunctionPlanner {
ScalarFunction::new_udf(map_udf(), vec![keys, values]),
)))
}
+
+ fn plan_any(&self, args: RawAnyAllExpr) -> Result<PlannerResult<RawAnyAllExpr>> {
+ let RawAnyAllExpr {
+ op,
+ needle,
+ haystack,
+ } = args;
+ let expr = match op {
+ BinaryOperator::Eq => Ok(array_has(haystack, needle)),
+ BinaryOperator::NotEq => {
+ let min = array_min(haystack.clone());
+ let max = array_max(haystack.clone());
+ // NOT EQ is true when either bound differs from left
+ let comparison =
+ min.not_eq(needle.clone()).or(max.clone().not_eq(needle));
+ any_op_with_null_handling(max, comparison, haystack)
+ }
+ BinaryOperator::Gt => {
+ let min = array_min(haystack.clone());
+ any_op_with_null_handling(min.clone(), min.lt(needle), haystack)
+ }
+ BinaryOperator::Lt => {
+ let max = array_max(haystack.clone());
+ any_op_with_null_handling(max.clone(), max.gt(needle), haystack)
+ }
+ BinaryOperator::GtEq => {
+ let min = array_min(haystack.clone());
+ any_op_with_null_handling(min.clone(), min.lt_eq(needle), haystack)
+ }
+ BinaryOperator::LtEq => {
+ let max = array_max(haystack.clone());
+ any_op_with_null_handling(max.clone(), max.gt_eq(needle), haystack)
+ }
+ _ => plan_err!(
+ "Unsupported AnyOp: '{op}', only '=', '<>', '>', '<', '>=', '<=' are supported"
+ ),
+ }?;
+ Ok(PlannerResult::Planned(expr))
+ }
+
+ fn plan_all(&self, args: RawAnyAllExpr) -> Result<PlannerResult<RawAnyAllExpr>> {
+ // CASE/WHEN structure:
+ // WHEN arr IS NULL → NULL
+ // WHEN empty → TRUE
+ // WHEN lhs IS NULL → NULL
+ // WHEN decisive_condition → FALSE
+ // WHEN has_nulls → NULL
+ // ELSE → TRUE
+ let RawAnyAllExpr {
+ op,
+ needle,
+ haystack,
+ } = args;
+ let null_arr_check = haystack.clone().is_null();
+ let empty_check = cardinality(haystack.clone()).eq(lit(0u64));
+ let null_lhs_check = needle.clone().is_null();
+ // DataFusion's array_position uses is_null() checks internally (not equality),
+ // so it can locate NULL elements even though NULL = NULL is NULL in standard SQL.
+ let has_nulls =
+ array_position(haystack.clone(), lit(ScalarValue::Null), lit(1i64))
+ .is_not_null();
+
+ let decisive_condition = match op {
Review Comment:
also moving this planning code into `datafusion-functions-nested` should allow us to more easily create dedicated UDFs for any/all without needing to expose these UDFs beyond the crate
- e.g. instead of needing to create new UDFs `array_has_all_eq`/`array_has_all_gt` that must be public for the planning code to reach it (from `sql/src/expr/mod.rs`) we can keep it private within this crate
related:
- #22102
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `plan_any`/`plan_all` to `ExprPlanner` to decouple functions from sql crate [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #22967:
URL: https://github.com/apache/datafusion/pull/22967#issuecomment-6406193596
Marked as draft after 14 days without activity: merge conflicts.
Please address these items and mark **Ready for review** when ready.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org