[
https://issues.apache.org/jira/browse/AVRO-3466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17510133#comment-17510133
]
Jack Klamer commented on AVRO-3466:
-----------------------------------
Thank you for reporting this! The test is super helpful. This looks related to
[https://github.com/apache/avro/pull/1615] . The current serialize
implementation for schema, while not derived, has the bug where the namespace
is not getting added for both Fixed and Enum types. (Just looked an confirmed).
Schema Ref and Schema Record both remember to add the namespace.
Schem Ref implementation (Correct):
{code:java}
Schema::Ref { ref name } =>
serializer.serialize_str(&name.fullname(None)),{code}
Schema Record implementation (Correct)
{code:java}
if let Some(ref n) = name.namespace {
map.serialize_entry("namespace", n)?;
}
map.serialize_entry("name", &name.name)?;
{code}
Enum/fixed (Incorrect)
{code}
// no namespace above this
map.serialize_entry("name", &name.name)?;
{code}
> Rust: serialize Schema to JSON loses inner namespace names
> ----------------------------------------------------------
>
> Key: AVRO-3466
> URL: https://issues.apache.org/jira/browse/AVRO-3466
> Project: Apache Avro
> Issue Type: Bug
> Components: rust
> Affects Versions: 1.11.1
> Environment: stable-x86_64-apple-darwin (default)
> rustc 1.56.1 (59eed8a2a 2021-11-01)
> apache-avro git commit a4e42112cea95 (master at the time)
>
> Reporter: Kevin
> Priority: Major
>
> Inner namespace for {{enum}} type in a Record field is lost when Schema
> serialized to JSON.
> An example failing Unit test for {{schema.rs}} demonstrates the problem:
> {code:java}
> #[test]
> fn kvc_test_to_json_inner_enum_inner_namespace() {
> let schema = r#"
> {
> "name": "record_name",
> "namespace": "space",
> "type": "record",
> "fields": [
> {
> "name": "outer_field_1",
> "type": [
> "null",
> {
> "type":"enum",
> "name":"inner_enum_name",
> "namespace": "inner_space",
> "symbols":["Extensive","Testing"]
> }
> ]
> },
> {
> "name": "outer_field_2",
> "type" : "inner_space.inner_enum_name"
> }
> ]
> }
> "#;
> let schema = Schema::parse_str(schema).unwrap();
> let rs = ResolvedSchema::try_from(&schema).expect("Schema didn't
> successfully parse");
> // confirm we have expected 2 full-names
> assert!(rs.get_names().len() == 2);
> for s in &["space.record_name", "inner_space.inner_enum_name"] {
> assert!(rs.get_names().contains_key(&Name::new(s).unwrap()));
> }
> // convert Schema back to JSON string
> // BUG: this operation loses the inner enum namespace "inner_space"
> let schema = serde_json::to_string(&schema).expect("test failed");
> println!("{}", schema);
> // confirm we can parse it again, this fails because JSON string lost
> inner enum namespace
> let _schema = Schema::parse_str(&schema).expect("test failed");
> } {code}
> above run against recent {{master}} (commit ) fails with:
> {code:java}
> {"type":"record","namespace":"space","name":"record_name","fields":[{"name":"outer_field_1","type":["null",{"type":"enum","name":"inner_enum_name","symbols":["Extensive","Testing"]}]},{"name":"outer_field_2","type":"inner_space.inner_enum_name"}]}test
> failed: ParsePrimitive("inner_space.inner_enum_name")
> thread 'schema::tests::kvc_test_to_json_inner_enum_inner_namespace' panicked
> at 'test failed: ParsePrimitive("inner_space.inner_enum_name")',
> avro/src/schema.rs:2862:50
> {code}
> Notice in the above that {{inner_enum_name}} in the output JSON is lacking
> the {{namespace}} attribute of the input JSON.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)