jonahgao commented on code in PR #15135:
URL: https://github.com/apache/datafusion/pull/15135#discussion_r1993710892


##########
datafusion/expr/src/logical_plan/plan.rs:
##########
@@ -2843,13 +2845,21 @@ impl Union {
                     )?
                 };
                 let nullable = fields.iter().any(|field| field.is_nullable());
-                let mut field = Field::new(name, data_type.clone(), nullable);
+
+                // Generate unique field name
+                let name = if let Some(count) = 
name_counts.get_mut(&base_name) {
+                    *count += 1;

Review Comment:
   Make sense to me👍. But it doesn't work for this case:
   ```sh
   > create table t1(a int);
   0 row(s) fetched.
   Elapsed 0.005 seconds.
   
   > create table t2(a int);
   0 row(s) fetched.
   Elapsed 0.007 seconds.
   
   > select * from t1,t2 union all select * from t1,t2;
   type_coercion
   caused by
   Schema error: Schema contains duplicate unqualified field name
   ```
   The above query works on the main branch.



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

Reply via email to