compiler-segfault commented on code in PR #12118:
URL: https://github.com/apache/arrow-rs/pull/12118#discussion_r4573449652
##########
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:
Added `test_resolve_multi_branch_union_with_writer_namespace_through_alias`
in 66dbd8bf: a three-branch `["null", "string", record]` union, so it goes
through `resolve_unions` and `find_best_union_match` instead of the
nullable-union shortcut, with the same alias + nested-writer-namespace setup.
It asserts `writer_to_reader.len() == 3` and that every writer branch has a
`Some` mapping.
Passing `reader_ns` for both sides makes that test produce `[Some((0,
Promotion(Direct))), Some((1, Promotion(Direct))), None]` — the nested record
branch is left unmapped, as you said. With the fix all three map. The
two-branch test stays as the nullable-shortcut counterpart.
`cargo test -p arrow-avro codec::` is 54/54 and `cargo clippy -p arrow-avro
--all-targets -- -D warnings` is clean.
--
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]