@@ -27,9 +27,8 @@ use std::sync::Arc;
2727use crate :: expr_fn:: binary_expr;
2828use crate :: function:: WindowFunctionSimplification ;
2929use crate :: logical_plan:: Subquery ;
30- use crate :: type_coercion:: functions:: value_fields_with_higher_order_udf;
3130use crate :: udhof:: HigherOrderUDF ;
32- use crate :: { AggregateUDF , LambdaParametersProgress , ValueOrLambda , Volatility } ;
31+ use crate :: { AggregateUDF , Volatility } ;
3332use crate :: { ExprSchemable , Operator , Signature , WindowFrame , WindowUDF } ;
3433
3534use arrow:: datatypes:: { DataType , Field , FieldRef } ;
@@ -40,7 +39,7 @@ use datafusion_common::tree_node::{
4039 Transformed , TransformedResult , TreeNode , TreeNodeContainer , TreeNodeRecursion ,
4140} ;
4241use datafusion_common:: {
43- Column , DFSchema , ExprSchema , HashMap , Result , ScalarValue , Spans , TableReference ,
42+ Column , DFSchema , HashMap , Result , ScalarValue , Spans , TableReference ,
4443} ;
4544use datafusion_expr_common:: placement:: ExpressionPlacement ;
4645use datafusion_functions_window_common:: field:: WindowUDFFieldArgs ;
@@ -444,32 +443,6 @@ impl HigherOrderFunction {
444443 pub fn name ( & self ) -> & str {
445444 self . func . name ( )
446445 }
447-
448- /// Invokes the inner function [`HigherOrderUDF::lambda_parameters`]
449- /// using the arguments of this invocation
450- pub fn lambda_parameters (
451- & self ,
452- schema : & dyn ExprSchema ,
453- ) -> Result < Vec < Vec < FieldRef > > > {
454- let args = self
455- . args
456- . iter ( )
457- . map ( |e| match e {
458- Expr :: Lambda ( lambda) => {
459- Ok ( ValueOrLambda :: Lambda ( Some ( lambda. body . to_field ( schema) ?. 1 ) ) )
460- }
461- _ => Ok ( ValueOrLambda :: Value ( e. to_field ( schema) ?. 1 ) ) ,
462- } )
463- . collect :: < Result < Vec < _ > > > ( ) ?;
464-
465- let coerced_fields =
466- value_fields_with_higher_order_udf ( & args, self . func . as_ref ( ) ) ?;
467-
468- match self . func . lambda_parameters ( 0 , & coerced_fields) ? {
469- LambdaParametersProgress :: Partial ( _) => todo ! ( ) ,
470- LambdaParametersProgress :: Complete ( items) => Ok ( items) ,
471- }
472- }
473446}
474447
475448impl Hash for HigherOrderFunction {
@@ -1395,16 +1368,38 @@ impl GroupingSet {
13951368#[ derive( Clone , PartialEq , Eq , PartialOrd , Hash , Debug ) ]
13961369pub struct Lambda {
13971370 /// The parameters names
1398- pub params : Vec < String > ,
1371+ pub params : LambdaParams ,
13991372 /// The body expression
14001373 pub body : Box < Expr > ,
14011374}
14021375
1376+ /// The params of a [Lambda]
1377+ #[ derive( Clone , PartialEq , Eq , PartialOrd , Hash , Debug ) ]
1378+ pub enum LambdaParams {
1379+ Bound ( Vec < FieldRef > ) ,
1380+ Unbound ( Vec < String > ) ,
1381+ }
1382+
1383+ impl LambdaParams {
1384+ pub fn names ( & self ) -> impl Iterator < Item = & str > {
1385+ let ( b, u) = match self {
1386+ LambdaParams :: Bound ( fields) => {
1387+ ( Some ( fields. iter ( ) . map ( |f| f. name ( ) . as_str ( ) ) ) , None )
1388+ }
1389+ LambdaParams :: Unbound ( items) => {
1390+ ( None , Some ( items. iter ( ) . map ( |n| n. as_str ( ) ) ) )
1391+ }
1392+ } ;
1393+
1394+ b. into_iter ( ) . flatten ( ) . chain ( u. into_iter ( ) . flatten ( ) )
1395+ }
1396+ }
1397+
14031398impl Lambda {
14041399 /// Create a new lambda expression
14051400 pub fn new ( params : Vec < String > , body : Expr ) -> Self {
14061401 Self {
1407- params,
1402+ params : LambdaParams :: Unbound ( params ) ,
14081403 body : Box :: new ( body) ,
14091404 }
14101405 }
@@ -3250,7 +3245,7 @@ impl Display for SchemaDisplay<'_> {
32503245 write ! (
32513246 f,
32523247 "({}) -> {}" ,
3253- display_comma_separated ( params) ,
3248+ params. names ( ) . collect :: < Vec <_>> ( ) . join ( ", " ) ,
32543249 SchemaDisplay ( body)
32553250 )
32563251 }
@@ -3436,7 +3431,12 @@ impl Display for SqlDisplay<'_> {
34363431 }
34373432 }
34383433 Expr :: Lambda ( Lambda { params, body } ) => {
3439- write ! ( f, "({}) -> {}" , params. join( ", " ) , SchemaDisplay ( body) )
3434+ write ! (
3435+ f,
3436+ "({}) -> {}" ,
3437+ params. names( ) . collect:: <Vec <_>>( ) . join( ", " ) ,
3438+ SchemaDisplay ( body)
3439+ )
34403440 }
34413441 _ => write ! ( f, "{}" , self . 0 ) ,
34423442 }
@@ -3759,7 +3759,11 @@ impl Display for Expr {
37593759 fmt_function ( f, fun. name ( ) , false , & fun. args , true )
37603760 }
37613761 Expr :: Lambda ( Lambda { params, body } ) => {
3762- write ! ( f, "({}) -> {body}" , params. join( ", " ) )
3762+ write ! (
3763+ f,
3764+ "({}) -> {body}" ,
3765+ params. names( ) . collect:: <Vec <_>>( ) . join( ", " )
3766+ )
37633767 }
37643768 Expr :: LambdaVariable ( c) => f. write_str ( & c. name ) ,
37653769 }
0 commit comments