gabotechs commented on code in PR #25418:
URL: https://github.com/apache/datafusion/pull/25418#discussion_r4048666047


##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -163,6 +163,16 @@ fn analyze_internal(
     // apply coercion rewrite all expressions in the plan individually
     plan.map_expressions(|expr| {
         let original_name = name_preserver.save(&expr);
+
+        // A lambda variable carries the field recorded when the plan was 
built, which
+        // need not be the one its function derives from the arguments. 
Resolve them
+        // before coercing, so lambda bodies are coerced against the types 
they receive.
+        let expr = if expr.exists(|e| Ok(matches!(e, 
Expr::HigherOrderFunction(_))))? {
+            expr.resolve_lambda_variables(&schema)?.data

Review Comment:
   We might also need to update `resolve_higher_order_function` to resolve 
non-lambda arguments unconditionally before deriving the enclosing function's 
lambda parameters.
   
   It currently only visits those arguments when `!vars.is_empty()`, and then 
returns `TreeNodeRecursion::Jump`. This misses a higher-order function used as 
a value argument at the outermost scope. It can be reproduced with something 
like this:
   
   ```sql
   array_any_match(array_transform(tags, x -> x), y -> y = 'c')
   ```
   
   If you manage to also add another test for this case that'd be awesome 🙏 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to