Jefffrey commented on code in PR #21416:
URL: https://github.com/apache/datafusion/pull/21416#discussion_r3098941505


##########
datafusion/sql/src/expr/mod.rs:
##########
@@ -1234,58 +1240,80 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
     }
 }
 
-/// Builds a CASE expression that handles NULL semantics for `x <op> ANY(arr)`:
+/// Plans `left_expr <compare_op> ANY/ALL(right_expr)` with proper SQL NULL 
semantics.
 ///
-/// ```text
-/// CASE
-///   WHEN <min_or_max>(arr) IS NOT NULL THEN <comparison>
-///   WHEN arr IS NOT NULL THEN FALSE          -- empty or all-null array
-///   ELSE NULL                                -- NULL array
-/// END
-/// ```
-fn any_op_with_null_handling(bound: Expr, comparison: Expr, arr: Expr) -> 
Result<Expr> {
-    when(bound.is_not_null(), comparison)
-        .when(arr.is_not_null(), lit(false))
-        .otherwise(lit(ScalarValue::Boolean(None)))
-}
-
-/// Plans a `<left> <op> ANY(<right>)` expression for non-subquery operands.
-fn plan_any_op(
-    left_expr: Expr,
-    right_expr: Expr,
+/// When `is_all` is false (ANY): returns TRUE if any element satisfies the 
condition.
+/// When `is_all` is true (ALL): returns TRUE if all elements satisfy the 
condition.
+///
+/// CASE/WHEN structure:
+///   WHEN arr IS NULL        → NULL
+///   WHEN empty              → is_all (ANY:false, ALL:true)
+///   WHEN lhs IS NULL        → NULL
+///   WHEN decisive_condition → !is_all (ANY:true match found, ALL:false 
violation found)
+///   WHEN has_nulls          → NULL
+///   ELSE                    → is_all (ANY:false, ALL:true)
+fn plan_quantified_op(
+    left_expr: &Expr,
+    right_expr: &Expr,
     compare_op: &BinaryOperator,
+    is_all: bool,

Review Comment:
   Probably more readable to have `is_all` be an enum instead
   
   ```rust
   // Or some better name
   enum QuantifyType {
       All,
       Any,
   }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to