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


##########
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:
   Checked check_metadata_with_storage_equal, which compares the entire 
metadata map (which is very strict) rather than just ARROW:extension:*, so 
keeping a dedicated extension helper avoids breaking non-extension metadata 
merging in UNION. Extracted extension_types_equal into a helper function. 



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