LiaCastaneda commented on code in PR #16454: URL: https://github.com/apache/datafusion/pull/16454#discussion_r2158853002
########## datafusion/core/src/physical_planner.rs: ########## @@ -969,8 +972,24 @@ impl DefaultPhysicalPlanner { // Remove temporary projected columns if left_projected || right_projected { - let final_join_result = - join_schema.iter().map(Expr::from).collect::<Vec<_>>(); + // Re-qualify the join schema only if the inputs were previously requalified in + // `try_new_with_project_input`. This ensures that when building the Projection + // it can correctly resolve field nullability and data types + // by disambiguating fields from the left and right sides of the join. + let qualified_join_schema = if requalified { + Arc::new(qualify_join_schema_sides( + join_schema, + original_left, + original_right, + )?) + } else { + Arc::clone(join_schema) + }; Review Comment: The rationale of qualifying the schema is that when building the logical `Projection` after, it will build the fields out of the expression names in [exprlist_to_fields](https://github.com/apache/datafusion/blob/d8ee8d894abf4f60a4799a0129be07c6e1f38473/datafusion/expr/src/logical_plan/plan.rs#L2189) so it will look in `new_join.schema()` and try to match each expr to a field in the schema, if the expr::Column does not have a qualifier and there are multiple candidates `Fields` that could correspond to this expr::Column , we will get an [ambiguity](https://github.com/apache/datafusion/blob/d8ee8d894abf4f60a4799a0129be07c6e1f38473/datafusion/common/src/dfschema.rs#L484) error, qualifying the schema allows us to prevent this. -- 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