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/06/22 13:53:33 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2765: Rewrite subexpressions of InSubquery in rewrite_expression

alamb commented on code in PR #2765:
URL: https://github.com/apache/arrow-datafusion/pull/2765#discussion_r903775768


##########
datafusion/optimizer/src/filter_push_down.rs:
##########
@@ -2045,4 +2045,37 @@ mod tests {
 
         Ok(())
     }
+
+    #[test]
+    fn test_in_subquery_with_alias() -> Result<()> {
+        // in table scan the true col name is 'test.a',
+        // but we rename it as 'b', and use col 'b' in subquery filter
+        let table_scan = test_table_scan()?;
+        let table_scan_sq = test_table_scan_with_name("sq")?;
+        let subplan = Arc::new(
+            LogicalPlanBuilder::from(table_scan_sq)
+                .project(vec![col("c")])?
+                .build()?,
+        );
+        let plan = LogicalPlanBuilder::from(table_scan)
+            .project(vec![col("a").alias("b"), col("c")])?
+            .filter(in_subquery(col("b"), subplan))?
+            .build()?;
+
+        // filter on col b in subquery
+        let expected_before = "\
+        Filter: #b IN (Subquery: Projection: #sq.c\n  TableScan: sq projection=None)\
+        \n  Projection: #test.a AS b, #test.c\
+        \n    TableScan: test projection=None";
+        assert_eq!(format!("{:?}", plan), expected_before);
+
+        // rewrite filter col b to test.a

Review Comment:
   👍 



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