You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/05/28 14:32:52 UTC

[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #2451: Add `EXISTS` and `IN` subquery rewriting for correlated filters at filter depth 1

jackwener commented on code in PR #2451:
URL: https://github.com/apache/arrow-datafusion/pull/2451#discussion_r884142166


##########
datafusion/core/src/optimizer/subquery_filter_to_join.rs:
##########
@@ -386,4 +504,112 @@ mod tests {
         assert_optimized_plan_eq(&plan, expected);
         Ok(())
     }
+
+    #[test]
+    fn test_exists_simple() -> Result<()> {
+        let table_a = test_table_scan_with_name("table_a")?;
+        let table_b = test_table_scan_with_name("table_b")?;
+        let subquery = LogicalPlanBuilder::from(table_b)
+            .filter(col("table_a.a").eq(col("table_b.a")))?
+            .build()?;
+
+        let plan = LogicalPlanBuilder::from(table_a)
+            .filter(exists(Arc::new(subquery)))?
+            .project(vec![col("a"), col("b")])?
+            .build()?;
+
+        let expected = "\
+            Projection: #table_a.a, #table_a.b [a:UInt32, b:UInt32]\
+            \n  Semi Join: #table_a.a = #table_b.a [a:UInt32, b:UInt32, c:UInt32]\
+            \n    TableScan: table_a projection=None [a:UInt32, b:UInt32, c:UInt32]\
+            \n    TableScan: table_b projection=None [a:UInt32, b:UInt32, c:UInt32]";
+
+        assert_optimized_plan_eq(&plan, expected);
+
+        Ok(())
+    }
+
+    #[test]
+    fn test_exists_multiple_correlated_filters() -> Result<()> {
+        let table_a = test_table_scan_with_name("table_a")?;
+        let table_b = test_table_scan_with_name("table_b")?;
+
+        // Test AND and nested filters will be extracted as join columns
+        let subquery = LogicalPlanBuilder::from(table_b)
+            .filter(
+                (col("table_a.c").eq(col("table_b.c"))).and(
+                    (col("table_a.a").eq(col("table_b.a")))
+                        .and(col("table_a.b").eq(col("table_b.b"))),

Review Comment:
   I think we need test like `A or (B and c)`?
   
   Because it can't be split .



-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org