jecsand838 commented on code in PR #8348:
URL: https://github.com/apache/arrow-rs/pull/8348#discussion_r2360021267
##########
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))
+ }
+ // Unions are validated separately (and disallowed as immediate
branches)
+ Schema::Union(_) => None,
+ }
+}
+
+fn union_first_duplicate<'a>(
+ branches: &'a [Schema<'a>],
+ enclosing_ns: Option<&'a str>,
+) -> Option<String> {
+ let mut seen: HashSet<UnionBranchKey> =
HashSet::with_capacity(branches.len());
Review Comment:
100%, I'm moving that.
##########
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))
+ }
+ // Unions are validated separately (and disallowed as immediate
branches)
+ Schema::Union(_) => None,
+ }
+}
+
+fn union_first_duplicate<'a>(
+ branches: &'a [Schema<'a>],
+ enclosing_ns: Option<&'a str>,
+) -> Option<String> {
+ let mut seen: HashSet<UnionBranchKey> =
HashSet::with_capacity(branches.len());
Review Comment:
100%, I'm removing that.
--
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]