@@ -2205,8 +2205,11 @@ mod tests {
22052205 use datafusion_common:: { assert_contains, DFSchemaRef , TableReference } ;
22062206 use datafusion_execution:: runtime_env:: RuntimeEnv ;
22072207 use datafusion_execution:: TaskContext ;
2208- use datafusion_expr:: { col, lit, LogicalPlanBuilder , UserDefinedLogicalNodeCore } ;
2208+ use datafusion_expr:: {
2209+ col, lit, LogicalPlanBuilder , Operator , UserDefinedLogicalNodeCore ,
2210+ } ;
22092211 use datafusion_functions_aggregate:: expr_fn:: sum;
2212+ use datafusion_physical_expr:: expressions:: { BinaryExpr , IsNotNullExpr } ;
22102213 use datafusion_physical_expr:: EquivalenceProperties ;
22112214 use datafusion_physical_plan:: execution_plan:: { Boundedness , EmissionType } ;
22122215
@@ -2723,6 +2726,49 @@ mod tests {
27232726
27242727 assert_eq ! ( col. name( ) , "metric:avg" ) ;
27252728 }
2729+
2730+ #[ tokio:: test]
2731+ async fn test_maybe_fix_nested_column_name_with_colon ( ) {
2732+ let schema =
2733+ Schema :: new ( vec ! [ Field :: new( "example_column" , DataType :: Int32 , false ) ] ) ;
2734+ let schema_ref: SchemaRef = Arc :: new ( schema) ;
2735+
2736+ // Construct the nested expr
2737+ let col_expr =
2738+ Arc :: new ( Column :: new ( "example_column:1" , 0 ) ) as Arc < dyn PhysicalExpr > ;
2739+ let is_not_null_expr = Arc :: new ( IsNotNullExpr :: new ( col_expr. clone ( ) ) ) ;
2740+
2741+ // Create a binary expression and put the column inside
2742+ let binary_expr = Arc :: new ( BinaryExpr :: new (
2743+ is_not_null_expr. clone ( ) ,
2744+ Operator :: Or ,
2745+ is_not_null_expr. clone ( ) ,
2746+ ) ) as Arc < dyn PhysicalExpr > ;
2747+
2748+ let fixed_expr =
2749+ maybe_fix_physical_column_name ( Ok ( binary_expr) , & schema_ref) . unwrap ( ) ;
2750+
2751+ let bin = fixed_expr
2752+ . as_any ( )
2753+ . downcast_ref :: < BinaryExpr > ( )
2754+ . expect ( "Expected BinaryExpr" ) ;
2755+
2756+ // Check that both sides where renamed
2757+ for expr in & [ bin. left ( ) , bin. right ( ) ] {
2758+ let is_not_null = expr
2759+ . as_any ( )
2760+ . downcast_ref :: < IsNotNullExpr > ( )
2761+ . expect ( "Expected IsNotNull" ) ;
2762+
2763+ let col = is_not_null
2764+ . arg ( )
2765+ . as_any ( )
2766+ . downcast_ref :: < Column > ( )
2767+ . expect ( "Expected Column" ) ;
2768+
2769+ assert_eq ! ( col. name( ) , "example_column" ) ;
2770+ }
2771+ }
27262772 struct ErrorExtensionPlanner { }
27272773
27282774 #[ async_trait]
0 commit comments