@@ -21,18 +21,15 @@ use datafusion_common::{
2121 HashMap ,
2222 tree_node:: { Transformed , TreeNodeRecursion , TreeNodeRewriter } ,
2323} ;
24- use datafusion_physical_expr:: {
25- PhysicalExpr ,
26- expressions:: Column ,
27- } ;
24+ use datafusion_physical_expr:: { PhysicalExpr , expressions:: Column } ;
2825
2926/// Rewrite column references in a physical expr according to a mapping.
3027///
3128/// This rewriter traverses the expression tree and replaces [`Column`] nodes
3229/// with the corresponding expression found in the `column_map`.
3330///
3431/// If a column is found in the map, it is replaced by the mapped expression.
35- /// If a column is NOT found in the ma an error is returned .
32+ /// If a column is NOT found in the map, it is left unchanged .
3633pub struct PhysicalColumnRewriter {
3734 /// Mapping from original column to new column.
3835 pub column_map : HashMap < Column , Arc < dyn PhysicalExpr > > ,
@@ -60,11 +57,8 @@ impl TreeNodeRewriter for PhysicalColumnRewriter {
6057 true ,
6158 TreeNodeRecursion :: Jump ,
6259 ) ) ;
63- } else {
64- return Err ( datafusion_common:: error:: DataFusionError :: Plan (
65- format ! ( "Column {:?} not found in column map" , column) ,
66- ) ) ;
6760 }
61+ // Column not in map - leave unchanged
6862 }
6963 Ok ( Transformed :: no ( node) )
7064 }
@@ -158,7 +152,7 @@ mod tests {
158152
159153 assert_eq ! (
160154 format!( "{}" , result. data) ,
161- "(42 + replaced_b) * (c - d) + e"
155+ "(42 + replaced_b) * (c@2 - d@3 ) + e@4 "
162156 ) ;
163157
164158 Ok ( ( ) )
@@ -192,7 +186,7 @@ mod tests {
192186
193187 assert_eq ! (
194188 format!( "{}" , result. data) ,
195- "a + b + 100 + new_col@5 + d + e"
189+ "a@0 + b@1 + 100 + new_col@5 + d@3 + e@4 "
196190 ) ;
197191
198192 Ok ( ( ) )
@@ -253,7 +247,7 @@ mod tests {
253247
254248 // Verify transformation occurred
255249 assert ! ( result. transformed) ;
256- assert_eq ! ( format!( "{}" , result. data) , "(10 + b) * (20 - d) + 30" ) ;
250+ assert_eq ! ( format!( "{}" , result. data) , "(10 + b@1 ) * (20 - d@3 ) + 30" ) ;
257251
258252 Ok ( ( ) )
259253 }
@@ -307,7 +301,7 @@ mod tests {
307301
308302 assert_eq ! (
309303 format!( "{}" , result. data) ,
310- "5 * a@0 + 3 - another_col@7 + b"
304+ "5 * a@0 + 3 - another_col@7 + b@1 "
311305 ) ;
312306
313307 // Verify transformation occurred
0 commit comments