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/04/25 21:39:30 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2339: Add `Expr::Exists` to represent EXISTS subquery expression

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


##########
datafusion/expr/src/expr_fn.rs:
##########
@@ -180,6 +182,13 @@ pub fn approx_percentile_cont_with_weight(
     }
 }
 
+/// Create an EXISTS subquery expression
+pub fn exists(subquery: LogicalPlan) -> Expr {

Review Comment:
   I wonder if this function should also be added to the prelude: https://github.com/apache/arrow-datafusion/blob/b890190a6521ab1e572184dcf6ea0a5afb3a47af/datafusion/core/src/prelude.rs#L33-L40



##########
datafusion/core/src/logical_plan/builder.rs:
##########
@@ -1339,6 +1341,31 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn exists_subquery() -> Result<()> {
+        let foo = test_table_scan_with_name("foo")?;
+        let bar = test_table_scan_with_name("bar")?;
+
+        let subquery = LogicalPlanBuilder::from(foo)
+            .project(vec![col("a")])?
+            .filter(col("a").eq(col("bar.a")))?
+            .build()?;
+
+        let outer_query = LogicalPlanBuilder::from(bar)
+            .project(vec![col("a")])?
+            .filter(exists(subquery))?

Review Comment:
   👌 



##########
datafusion/core/src/physical_plan/planner.rs:
##########
@@ -186,6 +186,9 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result<String> {
                 Ok(format!("{} IN ({:?})", expr, list))
             }
         }
+        Expr::Exists(_) => Err(DataFusionError::NotImplemented(
+            "EXISTS is not supported in the physical plan".to_string(),

Review Comment:
   ```suggestion
               "EXISTS is not yet supported in the physical plan".to_string(),
   ```



##########
datafusion/core/src/optimizer/utils.rs:
##########
@@ -223,6 +225,17 @@ pub fn from_plan(
             let right = &inputs[1];
             LogicalPlanBuilder::from(left).cross_join(right)?.build()
         }
+        LogicalPlan::Subquery(Subquery { .. }) => {
+            // let schema = inputs[0].schema().as_ref().clone().into();
+            // let schema =
+            //     DFSchemaRef::new(DFSchema::try_from_qualified_schema(alias, &schema)?);
+            // Ok(LogicalPlan::Subquery(Subquery {
+            //     subquery
+            //     input: Arc::new(inputs[0].clone()),
+            //     schema,
+            // }))
+            Err(DataFusionError::Plan("not implemented".to_string()))

Review Comment:
   ```suggestion
               Err(DataFusionError::Plan("subquery support is not full implemented yet".to_string()))
   ```



##########
datafusion/expr/src/expr_fn.rs:
##########
@@ -180,6 +182,13 @@ pub fn approx_percentile_cont_with_weight(
     }
 }
 
+/// Create an EXISTS subquery expression
+pub fn exists(subquery: LogicalPlan) -> Expr {

Review Comment:
   Maybe this function could take an `Arc<LogicalPlan>` so if someone already has one they can reuse it rather than making a copy to pass in here



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