gstvg commented on code in PR #21323:
URL: https://github.com/apache/datafusion/pull/21323#discussion_r3199619766


##########
datafusion/expr/src/higher_order_function.rs:
##########
@@ -224,35 +224,104 @@ pub struct LambdaArgument {
     /// per outer sublist), avoiding the per-call `Schema::new` build that
     /// includes constructing the internal name -> index map.
     schema: SchemaRef,
+    /// A RecordBatch containing the captured columns inside this lambda body, 
if any
+    ///
+    /// For example, for `array_transform([2], v -> v + a + b)`,
+    /// this will be a `RecordBatch` with two columns, `a` and `b`
+    captures: Option<RecordBatch>,
 }
 
 impl LambdaArgument {
-    pub fn new(params: Vec<FieldRef>, body: Arc<dyn PhysicalExpr>) -> Self {
-        let schema = Arc::new(Schema::new(params.clone()));
+    pub fn new(
+        params: Vec<FieldRef>,
+        body: Arc<dyn PhysicalExpr>,
+        captures: Option<RecordBatch>,
+    ) -> Self {
+        let fields = match &captures {
+            Some(batch) => batch
+                .schema_ref()
+                .fields()
+                .iter()
+                .cloned()
+                .chain(params.clone())
+                .collect(),
+            None => params.clone(),
+        };
+
+        let schema = Arc::new(Schema::new(fields));
+
         Self {
             params,
             body,
             schema,
+            captures,
         }
     }
 
     /// Evaluate this lambda
     /// `args` should evaluate to the value of each parameter
     /// of the correspondent lambda returned in 
[HigherOrderUDF::lambda_parameters].
+    ///
+    /// `adjust` should adjust the captured columns of this
+    /// lambda, if any, relative to it's parameters

Review Comment:
   
https://github.com/apache/datafusion/pull/21323/commits/2d1733354072c64a8b3f6d5aa63062ee704353c0
 Added an example showing all variations: sublists with multiple values 
(captured value repeated), empty sublist(captured value absent) and single 
value sublist (captured value copied once). I have been working on this a long 
time so it's hard for me to see it from the outside, if you think it's still 
hard to understand, please do ask for improvements, thanks



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