kumarUjjawal commented on code in PR #27544:
URL: https://github.com/apache/datafusion/pull/27544#discussion_r4675211705


##########
datafusion/optimizer/src/rewrite_set_comparison.rs:
##########
@@ -105,53 +107,50 @@ fn build_set_comparison_subquery(
         Box::new(right_expr),
     ));
 
-    let true_exists =
-        exists_subquery(&subquery, 
Expr::IsTrue(Box::new(comparison.clone())))?;
-    let null_exists =
-        exists_subquery(&subquery, 
Expr::IsNull(Box::new(comparison.clone())))?;
-
-    let result_expr = match quantifier {
-        SetQuantifier::Any => Expr::Case(expr::Case {
-            expr: None,
-            when_then_expr: vec![
-                (Box::new(true_exists), Box::new(lit(true))),
-                (
-                    Box::new(null_exists),
-                    Box::new(Expr::Literal(ScalarValue::Boolean(None), None)),
-                ),
-            ],
-            else_expr: Some(Box::new(lit(false))),
-        }),
-        SetQuantifier::All => {
-            let false_exists =
-                exists_subquery(&subquery, 
Expr::IsFalse(Box::new(comparison.clone())))?;
-            Expr::Case(expr::Case {
-                expr: None,
-                when_then_expr: vec![
-                    (Box::new(false_exists), Box::new(lit(false))),
-                    (
-                        Box::new(null_exists),
-                        Box::new(Expr::Literal(ScalarValue::Boolean(None), 
None)),
-                    ),
-                ],
-                else_expr: Some(Box::new(lit(true))),
-            })
-        }
+    let Subquery {
+        subquery: plan,
+        spans,
+        ..
+    } = subquery;
+    let null_exists = exists_subquery(
+        plan.as_ref().clone(),

Review Comment:
   Optional cleanup: `exists_subquery` take an `Arc<LogicalPlan>`? 
`LogicalPlanBuilder::from` already accepts it, so we could pass 
`Arc::clone(&plan)` here and move `plan` into the second call. Both filters 
would share the original plan without cloning its root.



-- 
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