jackwener commented on code in PR #4797:
URL: https://github.com/apache/arrow-datafusion/pull/4797#discussion_r1061477318


##########
datafusion/sql/src/planner.rs:
##########
@@ -3251,43 +3251,44 @@ fn ensure_any_column_reference_is_unambiguous(
     if schemas.len() == 1 {
         return Ok(());
     }
-
-    // extract columns both in one more schemas.
-    let mut column_count_map: HashMap<&str, usize> = HashMap::new();
-    schemas
+    // all referenced columns in the expression that don't have relation
+    let referenced_cols = expr.to_columns()?;
+    let mut no_relation_cols = referenced_cols
+        .iter()
+        .filter_map(|col| {
+            if col.relation.is_none() {
+                Some((col.name.as_str(), 0))
+            } else {
+                None
+            }
+        })
+        .collect::<HashMap<&str, u8>>();
+    // find the name of the column existing in multi schemas.
+    let ambiguous_col_name = schemas
         .iter()
         .flat_map(|schema| schema.fields())
-        .for_each(|field| {
-            column_count_map
-                .entry(field.name())
-                .and_modify(|v| *v += 1)
-                .or_insert(1usize);
+        .map(|field| field.name())

Review Comment:
   > Op, sorry we could not do this as the return type of `fields()` is 
`Vec<DFField>`.
   
   😂my mistake



-- 
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

Reply via email to