andygrove commented on code in PR #2344:
URL: https://github.com/apache/arrow-datafusion/pull/2344#discussion_r859206506


##########
datafusion/core/src/sql/planner.rs:
##########
@@ -4182,4 +4264,36 @@ mod tests {
             \n    TableScan: test projection=None";
         quick_test(sql, expected);
     }
+
+    #[test]
+    fn exists_subquery() {
+        let sql = "SELECT id FROM person p WHERE EXISTS \
+            (SELECT first_name FROM person \
+            WHERE last_name = p.last_name \
+            AND state = p.state)";
+
+        let expected = "Projection: #p.id\
+        \n  Filter: EXISTS (Subquery: Projection: #person.first_name\
+        \n  Filter: #person.last_name = #p.last_name AND #person.state = 
#p.state\
+        \n    TableScan: person projection=None)\
+        \n    SubqueryAlias: p\
+        \n      TableScan: person projection=None";
+        quick_test(sql, expected);
+    }
+
+    #[test]
+    fn exists_subquery_wildcard() {
+        let sql = "SELECT id FROM person p WHERE EXISTS \
+            (SELECT * FROM person \
+            WHERE last_name = p.last_name \
+            AND state = p.state)";
+
+        let expected = "Projection: #p.id\
+        \n  Filter: EXISTS (Subquery: Projection: #person.id, 
#person.first_name, #person.last_name, #person.age, #person.state, 
#person.salary, #person.birth_date, #person.😀\
+        \n  Filter: #person.last_name = #p.last_name AND #person.state = 
#p.state\
+        \n    TableScan: person projection=None)\
+        \n    SubqueryAlias: p\
+        \n      TableScan: person projection=None";

Review Comment:
   The query is hard to parse here and I have pushed a change to improve the 
formatting in the test. There is one filter in the subquery and one filter in 
the outer query.
   
   My plan was to implement an optimizer rule to handle re-writing to a 
semi-join. This rule would be applied regardless of whether the query was 
created by the SQL planner or via the DataFrame API. Does that make sense?



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

Reply via email to