alamb commented on code in PR #14384: URL: https://github.com/apache/datafusion/pull/14384#discussion_r1937555136
########## 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 +fn coerce_fields(common_type: DataType, lhs: &FieldRef, rhs: &FieldRef) -> FieldRef { + let is_nullable = lhs.is_nullable() || rhs.is_nullable(); + let name = lhs.name(); // pick the name from the left field Review Comment: I agree that would be better -- can I do it in a follow on PR? In my opinion this PR makes things better (doesn't lose field names) even though it is not perfect and I would like to fix the regression since 43 What I think we should do is switch `comparison_coercion` to use `type_union_coercion` eventually and then implement the correct coercion there -- 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