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/05/09 13:28:08 UTC
[avro] branch branch-1.11 updated: AVRO-3755: [Rust] Deserialization fails for reader schema with namespace (#2221)
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/branch-1.11 by this push:
new 51caca643 AVRO-3755: [Rust] Deserialization fails for reader schema with namespace (#2221)
51caca643 is described below
commit 51caca6438bfc05e1ba05cda710eda8f7250084e
Author: Martin Grigorov <ma...@users.noreply.github.com>
AuthorDate: Tue May 9 16:27:42 2023 +0300
AVRO-3755: [Rust] Deserialization fails for reader schema with namespace (#2221)
Add a unit test to prevent regressions.
The bug seems to be fixed earlier and most probably there is another
test test for the same but it does not harm to have a second one.
Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
(cherry picked from commit 903b5538900c6fdde996a5fe81cd324cf97ba538)
---
lang/rust/avro/src/schema.rs | 101 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index 5712784b8..70491acfd 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -4397,4 +4397,105 @@ mod tests {
// schema validation happens here
writer.append(avro_value).unwrap();
}
+
+ #[test]
+ fn avro_3755_deserialize() {
+ #[derive(
+ Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone, serde::Deserialize, serde::Serialize,
+ )]
+ pub enum Bar {
+ #[serde(rename = "bar0")]
+ Bar0,
+ #[serde(rename = "bar1")]
+ Bar1,
+ #[serde(rename = "bar2")]
+ Bar2,
+ }
+
+ #[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize)]
+ pub struct Foo {
+ #[serde(rename = "barInit")]
+ pub bar_init: Bar,
+ #[serde(rename = "barUse")]
+ pub bar_use: Bar,
+ }
+
+ let writer_schema = r#"{
+ "type": "record",
+ "name": "Foo",
+ "fields":
+ [
+ {
+ "name": "barInit",
+ "type":
+ {
+ "type": "enum",
+ "name": "Bar",
+ "symbols":
+ [
+ "bar0",
+ "bar1"
+ ]
+ }
+ },
+ {
+ "name": "barUse",
+ "type": "Bar"
+ }
+ ]
+ }"#;
+
+ let reader_schema = r#"{
+ "type": "record",
+ "name": "Foo",
+ "namespace": "name.space",
+ "fields":
+ [
+ {
+ "name": "barInit",
+ "type":
+ {
+ "type": "enum",
+ "name": "Bar",
+ "symbols":
+ [
+ "bar0",
+ "bar1",
+ "bar2"
+ ]
+ }
+ },
+ {
+ "name": "barUse",
+ "type": "Bar"
+ }
+ ]
+ }"#;
+
+ let writer_schema = Schema::parse_str(writer_schema).unwrap();
+ let foo = Foo {
+ bar_init: Bar::Bar0,
+ bar_use: Bar::Bar1,
+ };
+ let avro_value = crate::to_value(foo).unwrap();
+ assert!(
+ avro_value.validate(&writer_schema),
+ "value is valid for schema",
+ );
+ let datum = crate::to_avro_datum(&writer_schema, avro_value).unwrap();
+ let mut x = &datum[..];
+ let reader_schema = Schema::parse_str(reader_schema).unwrap();
+ let deser_value =
+ crate::from_avro_datum(&writer_schema, &mut x, Some(&reader_schema)).unwrap();
+ match deser_value {
+ types::Value::Record(fields) => {
+ assert_eq!(fields.len(), 2);
+ assert_eq!(fields[0].0, "barInit");
+ assert_eq!(fields[0].1, types::Value::Enum(0, "bar0".to_string()));
+ assert_eq!(fields[1].0, "barUse");
+ assert_eq!(fields[1].1, types::Value::Enum(1, "bar1".to_string()));
+ }
+ _ => panic!("Expected Value::Record"),
+ }
+ }
}