Matthew Cargille created AVRO-3755:
--------------------------------------
Summary: [Rust] Deserialization fails for reader schema with
namespace
Key: AVRO-3755
URL: https://issues.apache.org/jira/browse/AVRO-3755
Project: Apache Avro
Issue Type: Bug
Components: rust
Reporter: Matthew Cargille
Deserializing an avro value fails when using a reader schema with a namespace
in avro
0.14.0. Probably related to AVRO-3735. May be working in 0.15.0 but it's an
issue that's impacting our code and we'd like to double-check that a test case
will cover it.
Structs (from rs-gen)
{code:java}
#[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,
} {code}
Writer schema (serializes successfully)
{code:java}
fn get_raw_example_schema() -> String {
r#"{
"type": "record",
"name": "Foo",
"fields":
[
{
"name": "barInit",
"type":
{
"type": "enum",
"name": "Bar",
"symbols":
[
"bar0",
"bar1"
]
}
},
{
"name": "barUse",
"type": "Bar"
}
]
}"#
.to_string()
} {code}
Reader Schema
{code:java}
fn get_raw_example_schema_v2() -> String {
r#"{
"type": "record",
"name": "Foo",
"namespace": "name.space",
"fields":
[
{
"name": "barInit",
"type":
{
"type": "enum",
"name": "Bar",
"symbols":
[
"bar0",
"bar1",
"bar2"
]
}
},
{
"name": "barUse",
"type": "Bar"
}
]
}"#
.to_string()
} {code}
Test code:
{code:java}
#[test]
fn test_deserialize() {
testing_logger::setup();
let schema = Schema::parse_str(&get_raw_example_schema()).unwrap();
let foo = Foo {
bar_init: Bar::Bar0,
bar_use: Bar::Bar1,
}; let avro_value = to_value(foo).unwrap();
println!(
"value is valid for schema: {}",
avro_value.validate(&schema)
); let datum = to_avro_datum(&schema, avro_value).unwrap();
let mut x = &datum[..];
let read_schema = Schema::parse_str(&get_raw_example_schema_v2()).unwrap();
let deser_value = from_avro_datum(&schema, &mut x,
Some(&read_schema)).unwrap();
testing_logger::validate(|logs| {
for log in logs {
println!("{}", log.body)
}
});
} {code}
error
{code:java}
panicked at 'called `Result::unwrap()` on an `Err` value:
SchemaResolutionError(Name { name: "Bar", namespace: None }) {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)