@@ -39,6 +39,7 @@ use datafusion_functions_aggregate::expr_fn::{
3939 array_agg, avg, avg_distinct, count, count_distinct, max, median, min, sum,
4040 sum_distinct,
4141} ;
42+ use datafusion_functions_nested:: expr_fn:: { array_filter, array_transform, make_array} ;
4243use datafusion_functions_nested:: make_array:: make_array_udf;
4344use datafusion_functions_window:: expr_fn:: { first_value, lead, row_number} ;
4445use insta:: assert_snapshot;
@@ -78,8 +79,8 @@ use datafusion_expr::{
7879 CreateMemoryTable , CreateView , DdlStatement , Expr , ExprFunctionExt , ExprSchemable ,
7980 LogicalPlan , LogicalPlanBuilder , ScalarFunctionImplementation , SortExpr , TableType ,
8081 WindowFrame , WindowFrameBound , WindowFrameUnits , WindowFunctionDefinition , cast, col,
81- create_udf, exists, in_subquery, lit, out_ref_col, placeholder, scalar_subquery ,
82- when, wildcard,
82+ create_udf, exists, in_subquery, lambda , lambda_var , lit, out_ref_col, placeholder,
83+ scalar_subquery , when, wildcard,
8384} ;
8485use datafusion_physical_expr:: Partitioning ;
8586use datafusion_physical_expr:: aggregate:: AggregateExprBuilder ;
@@ -90,7 +91,9 @@ use datafusion_physical_plan::aggregates::{
9091 AggregateExec , AggregateMode , PhysicalGroupBy ,
9192} ;
9293use datafusion_physical_plan:: empty:: EmptyExec ;
93- use datafusion_physical_plan:: { ExecutionPlan , ExecutionPlanProperties , displayable} ;
94+ use datafusion_physical_plan:: {
95+ ExecutionPlan , ExecutionPlanProperties , collect, displayable,
96+ } ;
9497
9598use datafusion:: error:: Result as DataFusionResult ;
9699use datafusion:: execution:: options:: JsonReadOptions ;
@@ -7238,3 +7241,45 @@ async fn test_grouping_with_alias() -> Result<()> {
72387241
72397242 Ok ( ( ) )
72407243}
7244+
7245+ #[ tokio:: test]
7246+ async fn test_unresolved_lambda_variable ( ) -> Result < ( ) > {
7247+ let plan = table_with_mixed_lists ( )
7248+ . await ?
7249+ . with_column (
7250+ "c" ,
7251+ array_transform (
7252+ make_array ( vec ! [ col( "list" ) ] ) ,
7253+ lambda (
7254+ [ "x" ] ,
7255+ array_filter (
7256+ lambda_var ( "x" ) ,
7257+ lambda ( [ "y" ] , lambda_var ( "y" ) . gt_eq ( lit ( 2 ) ) ) ,
7258+ ) ,
7259+ ) ,
7260+ ) ,
7261+ ) ?
7262+ . select_columns ( & [ "list" , "c" ] ) ?
7263+ . into_unoptimized_plan ( )
7264+ . resolve_lambda_variables ( ) ?
7265+ . data ;
7266+
7267+ let session = SessionContext :: new ( ) ;
7268+ let exec = session. state ( ) . create_physical_plan ( & plan) . await ?;
7269+ let context = session. task_ctx ( ) ;
7270+ let results = collect ( exec, context) . await ?;
7271+
7272+ let expected = [
7273+ "+-----------+----------+" ,
7274+ "| list | c |" ,
7275+ "+-----------+----------+" ,
7276+ "| [1, 2, 3] | [[2, 3]] |" ,
7277+ "| | [] |" ,
7278+ "| [] | [[]] |" ,
7279+ "| | [] |" ,
7280+ "+-----------+----------+" ,
7281+ ] ;
7282+ assert_batches_eq ! ( expected, & results) ;
7283+
7284+ Ok ( ( ) )
7285+ }
0 commit comments