alamb commented on code in PR #14384:
URL: https://github.com/apache/datafusion/pull/14384#discussion_r1937405278


##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -961,23 +961,31 @@ fn struct_coercion(lhs_type: &DataType, rhs_type: 
&DataType) -> Option<DataType>
                 return None;
             }
 
-            let types = std::iter::zip(lhs_fields.iter(), rhs_fields.iter())
+            let coerced_types = std::iter::zip(lhs_fields.iter(), 
rhs_fields.iter())
                 .map(|(lhs, rhs)| comparison_coercion(lhs.data_type(), 
rhs.data_type()))
                 .collect::<Option<Vec<DataType>>>()?;
 
-            let fields = types
+            // preserve the field name and nullability
+            let orig_fields = std::iter::zip(lhs_fields.iter(), 
rhs_fields.iter());
+
+            let fields: Vec<FieldRef> = coerced_types
                 .into_iter()
-                .enumerate()
-                .map(|(i, datatype)| {
-                    Arc::new(Field::new(format!("c{i}"), datatype, true))
-                })
-                .collect::<Vec<FieldRef>>();
+                .zip(orig_fields)
+                .map(|(datatype, (lhs, rhs))| coerce_fields(datatype, lhs, 
rhs))
+                .collect();
             Some(Struct(fields.into()))
         }
         _ => None,
     }
 }
 
+/// returns the result of coercing two fields to a common type

Review Comment:
   here is the fix. I suspect this doesn't matter in most cases as the result 
of a comparison is `boolean` so the names of the intermediate fields don't 
matter. 
   
   However, in a `CASE` (and union for that matter) the names do matter, so 
this PR preserves them



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