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

[jira] [Commented] (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:comment-tabpanel&focusedCommentId=17720929#comment-17720929 ] 

ASF subversion and git services commented on AVRO-3755:
-------------------------------------------------------

Commit d776a7f83330fdf431ce3fc7dae501362372716d in avro's branch refs/heads/avro-3755-add-unit-test from Martin Tzvetanov Grigorov
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=d776a7f83 ]

AVRO-3755: [Rust] Deserialization fails for reader schema with namespace

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>


> [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
>            Priority: Major
>
> 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)