Rich-T-kid commented on code in PR #12118:
URL: https://github.com/apache/arrow-rs/pull/12118#discussion_r4571855113


##########
arrow-avro/src/codec.rs:
##########
@@ -2434,12 +2480,105 @@ mod tests {
         Schema::Union(branches)
     }
 
+    fn mk_schema(s: &'static str) -> Schema<'static> {
+        serde_json::from_str(s).unwrap()
+    }
+
+    #[test]
+    fn test_resolve_nested_record_with_inherited_namespace() {
+        // The writer spells out the namespace that the nested record inherits 
from
+        // its enclosing record; the reader leaves it implicit. Both nested 
records
+        // have the full name "ns.Bw", so the schemas resolve against each 
other.
+        let writer = mk_schema(
+            r#"{
+                "type": "record", "name": "B", "namespace": "ns",
+                "fields": [{
+                    "name": "nested",
+                    "type": {"type": "record", "name": "Bw", "namespace": "ns",
+                             "fields": [{"name": "x", "type": "int"}]}
+                }]
+            }"#,
+        );
+        let reader = mk_schema(
+            r#"{
+                "type": "record", "name": "B", "namespace": "ns",
+                "fields": [{
+                    "name": "nested",
+                    "type": {"type": "record", "name": "Bw",
+                             "fields": [{"name": "x", "type": "int"}]}
+                }]
+            }"#,
+        );
+        let mut maker = Maker::new(false, false, Tz::default());
+        let result = maker.make_data_type(&writer, Some(&reader), None, None);
+        assert!(result.is_ok(), "unexpected error: {result:?}");
+    }
+
+    #[test]
+    fn test_resolve_nested_record_with_writer_namespace_through_alias() {
+        // The reader matches the writer's `writer_ns.B` through an alias, so 
its
+        // own namespace is `reader_ns`. The nested writer record inherits
+        // `writer_ns` while the reader spells that full name out, so both 
nested
+        // records are `writer_ns.Bw` and must resolve.
+        let writer = mk_schema(
+            r#"{
+                "type": "record", "name": "B", "namespace": "writer_ns",
+                "fields": [{
+                    "name": "nested",
+                    "type": {"type": "record", "name": "Bw",
+                             "fields": [{"name": "x", "type": "int"}]}
+                }]
+            }"#,
+        );
+        let reader = mk_schema(
+            r#"{
+                "type": "record", "name": "B", "namespace": "reader_ns",
+                "aliases": ["writer_ns.B"],
+                "fields": [{
+                    "name": "nested",
+                    "type": {"type": "record", "name": "Bw", "namespace": 
"writer_ns",
+                             "fields": [{"name": "x", "type": "int"}]}
+                }]
+            }"#,
+        );
+        let mut maker = Maker::new(false, false, Tz::default());
+        let result = maker.make_data_type(&writer, Some(&reader), None, None);
+        assert!(result.is_ok(), "unexpected error: {result:?}");
+    }
+
+    #[test]
+    fn test_resolve_union_branch_with_inherited_namespace() {
+        let writer = mk_schema(
+            r#"{
+                "type": "record", "name": "B", "namespace": "ns",
+                "fields": [{
+                    "name": "nested",
+                    "type": ["null", {"type": "record", "name": "Bw", 
"namespace": "ns",

Review Comment:
   Could we make this use the multi-branch union from #11960 and assert that 
each writer branch has a reader mapping? The current `["null", record]` case 
takes the nullable-union shortcut, so it doesn’t exercise `resolve_unions` or 
`find_best_union_match`. I changed that path back to use `reader_ns` for both 
sides and the existing resolution tests still passed; a three-branch case 
catches it because the nested record branch is left unmapped.



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

Reply via email to