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


##########
datafusion/optimizer/src/decorrelate_where_exists.rs:
##########
@@ -137,8 +137,14 @@ fn optimize_exists(
     let subqry_inputs = query_info.query.subquery.inputs();
     let subqry_input = only_or_err(subqry_inputs.as_slice())
         .map_err(|e| context!("single expression projection required", e))?;
-    let subqry_filter = Filter::try_from_plan(subqry_input)
-        .map_err(|e| context!("cannot optimize non-correlated subquery", e))?;
+    let subqry_filter = match subqry_input {

Review Comment:
   I would like to see something with explicit pattern matching to make sure we 
are only supporting intended cases. Here is my attempt:
   
   ```rust
   fn optimize_exists(
       query_info: &SubqueryInfo,
       outer_input: &LogicalPlan,
       outer_other_exprs: &[Expr],
   ) -> datafusion_common::Result<LogicalPlan> {
   
       let subqry_filter = match query_info.query.subquery.as_ref() {
           LogicalPlan::Distinct(subqry_distinct) => match 
subqry_distinct.input.as_ref() {
               LogicalPlan::Projection(subqry_proj) => 
Filter::try_from_plan(&*subqry_proj.input),
               _ => Err(DataFusionError::NotImplemented("todo: error 
message".to_string()))
           }
           LogicalPlan::Projection(subqry_proj) =>  
Filter::try_from_plan(&*subqry_proj.input),
           _ => Err(DataFusionError::NotImplemented("todo: error 
message".to_string()))
       }.map_err(|e| context!("cannot optimize non-correlated subquery", e))?;
   ```



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