cyberbeam524 commented on code in PR #27788:
URL: https://github.com/apache/datafusion/pull/27788#discussion_r4783663674
##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -2012,6 +2032,47 @@ mod test {
)
}
+ #[test]
+ fn coerce_union_schema_extension_type() -> Result<()> {
+ use super::coerce_union_schema;
+ use arrow_schema::extension::EXTENSION_TYPE_NAME_KEY;
+ let input = |data_type: DataType, extension: Option<&str>| {
+ let mut field = Field::new("c", data_type, true);
+ if let Some(extension) = extension {
+ field = field.with_metadata(std::collections::HashMap::from([(
+ EXTENSION_TYPE_NAME_KEY.to_string(),
+ extension.to_string(),
+ )]));
+ }
+ DFSchema::from_unqualified_fields(
+ vec![field].into(),
+ std::collections::HashMap::new(),
+ )
+ .map(|schema| {
+ Arc::new(LogicalPlan::EmptyRelation(EmptyRelation {
+ produce_one_row: false,
+ schema: Arc::new(schema),
+ }))
+ })
+ };
+
+ // No input stores arrow.uuid as Binary, so the result drops it
+ let schema = coerce_union_schema(&[
+ input(DataType::FixedSizeBinary(16), Some("arrow.uuid"))?,
+ input(DataType::Binary, None)?,
+ ])?;
+ assert_eq!(schema.field(0).data_type(), &DataType::Binary);
+ assert_eq!(schema.field(0).extension_type_name(), None);
+
+ // A NULL input's extension type does not decide the result
+ let schema = coerce_union_schema(&[
+ input(DataType::Null, Some("arrow.opaque"))?,
+ input(Utf8, Some("arrow.json"))?,
+ ])?;
+ assert_eq!(schema.field(0).extension_type_name(), Some("arrow.json"));
Review Comment:
@paleolimbot Out of curiosity, for non-extension types, null_coercion always
resolves Null + T -> T verbatim. With future extension-aware coercion, would a
Null-backed extension type (Null<ext_A>) unioned with a different extension
type (T<ext_B>) be treated as a conflicting extension pair (e.g., dropping both
or erroring) rather than letting T<ext_B> win?
--
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]