You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2023/08/15 07:10:12 UTC
[avro] 09/09: AVRO-3814: [Rust] Use types::Value::resolve_internal() instead of validate_internal()
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch avro-3814/schema-resolution-union
in repository https://gitbox.apache.org/repos/asf/avro.git
commit 088459db4635f0dd2ad7ea8f8c49627a8c7880c8
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Tue Aug 15 10:08:34 2023 +0300
AVRO-3814: [Rust] Use types::Value::resolve_internal() instead of validate_internal()
... when looking for the matching schema in an union
Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
lang/rust/avro/src/schema.rs | 5 +++--
lang/rust/avro/src/types.rs | 2 +-
lang/rust/avro/tests/avro-3786.rs | 20 ++++++++++----------
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index 22307d4e4..0c3ce3351 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -840,8 +840,9 @@ impl UnionSchema {
// Attempt to validate the value in order to ensure we've selected the right schema.
value
- .validate_internal(schema, &collected_names, namespace, true)
- .is_none()
+ .clone()
+ .resolve_internal(schema, &collected_names, namespace, &None)
+ .is_ok()
})
}
}
diff --git a/lang/rust/avro/src/types.rs b/lang/rust/avro/src/types.rs
index 4ba6a77fe..2a812c3af 100644
--- a/lang/rust/avro/src/types.rs
+++ b/lang/rust/avro/src/types.rs
@@ -656,7 +656,7 @@ impl Value {
self.resolve_internal(schema, rs.get_names(), &enclosing_namespace, &None)
}
- fn resolve_internal(
+ pub(crate) fn resolve_internal(
mut self,
schema: &Schema,
names: &NamesRef,
diff --git a/lang/rust/avro/tests/avro-3786.rs b/lang/rust/avro/tests/avro-3786.rs
index 437889ed7..d27e0c4e5 100644
--- a/lang/rust/avro/tests/avro-3786.rs
+++ b/lang/rust/avro/tests/avro-3786.rs
@@ -248,10 +248,10 @@ fn avro_3786_deserialize_union_with_different_enum_order_defined_in_record() ->
]
}"#;
let writer_schema = Schema::parse_str(writer_schema)?;
- let foo = Foo {
+ let foo1 = Foo {
bar_parent: Some(BarParent { bar: Bar::Bar0 }),
};
- let avro_value = crate::to_value(foo)?;
+ let avro_value = crate::to_value(foo1)?;
assert!(
avro_value.validate(&writer_schema),
"value is valid for schema",
@@ -361,10 +361,10 @@ fn test_avro_3786_deserialize_union_with_different_enum_order_defined_in_record_
]
}"#;
let writer_schema = Schema::parse_str(writer_schema)?;
- let foo = Foo {
+ let foo1 = Foo {
bar_parent: Some(BarParent { bar: Bar::Bar1 }),
};
- let avro_value = crate::to_value(foo)?;
+ let avro_value = crate::to_value(foo1)?;
assert!(
avro_value.validate(&writer_schema),
"value is valid for schema",
@@ -474,10 +474,10 @@ fn test_avro_3786_deserialize_union_with_different_enum_order_defined_in_record_
]
}"#;
let writer_schema = Schema::parse_str(writer_schema)?;
- let foo = Foo {
+ let foo1 = Foo {
bar_parent: Some(BarParent { bar: Bar::Bar1 }),
};
- let avro_value = crate::to_value(foo)?;
+ let avro_value = crate::to_value(foo1)?;
assert!(
avro_value.validate(&writer_schema),
"value is valid for schema",
@@ -587,10 +587,10 @@ fn deserialize_union_with_different_enum_order_defined_in_record() -> TestResult
]
}"#;
let writer_schema = Schema::parse_str(writer_schema)?;
- let foo = Foo {
+ let foo1 = Foo {
bar_parent: Some(BarParent { bar: Bar::Bar2 }),
};
- let avro_value = crate::to_value(foo)?;
+ let avro_value = crate::to_value(foo1)?;
assert!(
avro_value.validate(&writer_schema),
"value is valid for schema",
@@ -853,7 +853,7 @@ fn deserialize_union_with_record_with_enum_defined_inline_reader_has_different_i
]
}"#;
let writer_schema = Schema::parse_str(writer_schema)?;
- let foo = Foo {
+ let foo1 = Foo {
bar_init: Bar::Bar0,
baz: Baz::Baz0,
parent: Some(Parent {
@@ -864,7 +864,7 @@ fn deserialize_union_with_record_with_enum_defined_inline_reader_has_different_i
defined_in_record: DefinedInRecord::Val1,
}),
};
- let avro_value = crate::to_value(foo)?;
+ let avro_value = crate::to_value(foo1)?;
assert!(
avro_value.validate(&writer_schema),
"value is valid for schema",