jecsand838 commented on code in PR #8348: URL: https://github.com/apache/arrow-rs/pull/8348#discussion_r2360014415
########## arrow-avro/src/codec.rs: ########## @@ -915,6 +1020,76 @@ fn nullable_union_variants<'x, 'y>( } } +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +enum UnionBranchKey { + Named(String), + Primitive(PrimitiveType), + Array, + Map, +} + +fn branch_key_of<'a>(s: &Schema<'a>, enclosing_ns: Option<&'a str>) -> Option<UnionBranchKey> { + match s { + // Primitives + Schema::TypeName(TypeName::Primitive(p)) => Some(UnionBranchKey::Primitive(*p)), + Schema::Type(Type { + r#type: TypeName::Primitive(p), + .. + }) => Some(UnionBranchKey::Primitive(*p)), + // Named references + Schema::TypeName(TypeName::Ref(name)) => { + let (full, _) = make_full_name(name, None, enclosing_ns); + Some(UnionBranchKey::Named(full)) + } + Schema::Type(Type { + r#type: TypeName::Ref(name), + .. + }) => { + let (full, _) = make_full_name(name, None, enclosing_ns); + Some(UnionBranchKey::Named(full)) + } + // Complex non‑named + Schema::Complex(ComplexType::Array(_)) => Some(UnionBranchKey::Array), + Schema::Complex(ComplexType::Map(_)) => Some(UnionBranchKey::Map), + // Inline named definitions + Schema::Complex(ComplexType::Record(r)) => { + let (full, _) = make_full_name(r.name, r.namespace, enclosing_ns); + Some(UnionBranchKey::Named(full)) + } + Schema::Complex(ComplexType::Enum(e)) => { + let (full, _) = make_full_name(e.name, e.namespace, enclosing_ns); + Some(UnionBranchKey::Named(full)) + } + Schema::Complex(ComplexType::Fixed(f)) => { + let (full, _) = make_full_name(f.name, f.namespace, enclosing_ns); + Some(UnionBranchKey::Named(full)) + } Review Comment: That's much cleaner. Ty for that suggestion. -- 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...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org