houqp commented on a change in pull request #605: URL: https://github.com/apache/arrow-datafusion/pull/605#discussion_r664709088
########## File path: datafusion/src/logical_plan/expr.rs ########## @@ -89,14 +89,46 @@ impl Column { /// /// For example, `foo` will be normalized to `t.foo` if there is a /// column named `foo` in a relation named `t` found in `schemas` - pub fn normalize(self, schemas: &[&DFSchemaRef]) -> Result<Self> { + pub fn normalize(self, plan: &LogicalPlan) -> Result<Self> { if self.relation.is_some() { return Ok(self); } - for schema in schemas { - if let Ok(field) = schema.field_with_unqualified_name(&self.name) { - return Ok(field.qualified_column()); + let schemas = plan.all_schemas(); + let using_columns = plan.using_columns()?; + + for schema in &schemas { + let fields = schema.fields_with_unqualified_name(&self.name); + match fields.len() { + 0 => continue, Review comment: We are iterating through schemas from all plan nodes in the provided plan tree, each plan node could have different schemas, so when we do the `fields_with_unqualified_name` look up, some of these plan nodes will no contain a field that matches `self.name`. We just pick the first plan node that contains schema field matches the unqualified name. -- 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...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org