You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Martin Tzvetanov Grigorov (Jira)" <ji...@apache.org> on 2023/05/09 13:29:00 UTC

[jira] [Resolved] (AVRO-3755) [Rust] Deserialization fails for reader schema with namespace

     [ https://issues.apache.org/jira/browse/AVRO-3755?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Tzvetanov Grigorov resolved AVRO-3755.
---------------------------------------------
    Fix Version/s: 1.12.0
                   1.11.2
         Assignee: Martin Tzvetanov Grigorov
       Resolution: Fixed

> [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
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.12.0, 1.11.2
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> 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)