tschwarzinger commented on code in PR #27788:
URL: https://github.com/apache/datafusion/pull/27788#discussion_r4718474179


##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -1721,11 +1721,53 @@ fn coerce_union_schema_with_schema(
         .iter()
         .enumerate()
         .map(|(i, field)| {
+            let input_fields: Vec<&Field> = inputs
+                .iter()
+                .map(|plan| plan.schema().field(i).as_ref())
+                .collect();
+
+            // Validate extension type compatibility across non-Null inputs.
+            // Merging extension metadata onto a widened storage type (e.g.
+            // FixedSizeBinary(16)<arrow.uuid> + Binary -> Binary) produces an
+            // invalid logical schema that causes internal errors on UNION and
+            // silently drops the extension type on UNION ALL.
+            if let Some(ext_field) = input_fields
+                .iter()
+                .find(|f| f.extension_type_name().is_some())
+            {
+                let ext_name = ext_field.extension_type_name();
+                let ext_meta = ext_field.extension_type_metadata();
+                for other in &input_fields {
+                    if matches!(other.data_type(), DataType::Null) {
+                        continue;
+                    }
+                    if other.extension_type_name() != ext_name

Review Comment:
   Do we have somewhere a helper function to check whether two fields with 
extension types are "equivalent". Starting now with extracting this check into 
a single place might make it easier in the future to make this behavior more 
lenient (e.g., https://github.com/apache/datafusion/issues/26810).
   
   Even if we stay strict with the comparison, it would be good to have that in 
a single place. Could also be a follow-up if it does not yet exist where we 
search for existing usages in the code.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to