LiaCastaneda commented on code in PR #15580: URL: https://github.com/apache/datafusion/pull/15580#discussion_r2030945282
########## datafusion/core/src/physical_planner.rs: ########## @@ -2061,6 +2066,35 @@ fn tuple_err<T, R>(value: (Result<T>, Result<R>)) -> Result<(T, R)> { } } +// Handle the case where the name of a physical column expression does not match the corresponding physical input fields names. +// Physical column names are derived from the physical schema, whereas physical column expressions are derived from the logical column names. +// +// This is a special case that applies only to column expressions. Logical plans may slightly modify column names by appending a suffix (e.g., using ':'), +// to avoid duplicates—since DFSchemas do not allow duplicate names. For example: `count(Int64(1)):1`. +fn maybe_fix_physical_column_name( + expr: Result<Arc<dyn PhysicalExpr>>, + input_physical_schema: &SchemaRef, +) -> Result<Arc<dyn PhysicalExpr>> { + if let Ok(e) = &expr { + if let Some(column) = e.as_any().downcast_ref::<Column>() { + let physical_field = input_physical_schema.field(column.index()); + let expr_col_name = column.name(); + let physical_name = physical_field.name(); + + if physical_name != expr_col_name { + if let Some(idx) = expr_col_name.find(':') { Review Comment: I was aiming at the first match, since there are some (unlikely but possible) cases where renaming can have two or more ':' like a:1 a:1:1 -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org