avantgardnerio commented on code in PR #3287:
URL: https://github.com/apache/arrow-datafusion/pull/3287#discussion_r957699164


##########
datafusion/optimizer/src/decorrelate_scalar_subquery.rs:
##########
@@ -173,20 +191,28 @@ fn optimize_scalar(
         .map_err(|e| context!("Exactly one input is expected. Is this a 
join?", e))?;
     let aggr = Aggregate::try_from_plan(sub_input)
         .map_err(|e| context!("scalar subqueries must aggregate a value", e))?;
-    let filter = Filter::try_from_plan(&aggr.input).map_err(|e| {
-        context!("scalar subqueries must have a filter to be correlated", e)
-    })?;
+    let filter = Filter::try_from_plan(&aggr.input).ok();
+
+    // if there were filters, we use that logical plan, otherwise the plan 
from the aggregate
+    let input: &LogicalPlan;

Review Comment:
   Sorry, I was going to pull and compile, but I see you undrafted, so here's 
what I think will compile and avoid the unwrap() (which we're trying to 
elliminate for audit purposes even if it should be safe):
   
   ```
       let input = match filter {
           Some(filter) => &filter.input,
           None => &aggr.input
       };
       ```



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