[ 
https://issues.apache.org/jira/browse/AVRO-3433?focusedWorklogId=737815&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-737815
 ]

ASF GitHub Bot logged work on AVRO-3433:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 07/Mar/22 21:49
            Start Date: 07/Mar/22 21:49
    Worklog Time Spent: 10m 
      Work Description: travisbrown commented on a change in pull request #1582:
URL: https://github.com/apache/avro/pull/1582#discussion_r821131779



##########
File path: lang/rust/avro/src/types.rs
##########
@@ -1323,4 +1356,269 @@ mod tests {
             JsonValue::String("936da01f-9abd-4d9d-80c7-02af85c822a8".into())
         );
     }
+
+    #[test]
+    fn test_recursive_resolves() {
+        let schema = Schema::parse_str(
+            r#"
+        {
+            "type":"record",
+            "name":"TestStruct",
+            "fields": [
+                {
+                    "name":"a",
+                    "type":{
+                        "type":"record",
+                        "name": "Inner",
+                        "fields": [ {
+                            "name":"z",
+                            "type":"int"
+                        }]
+                    }
+                },
+                {
+                    "name":"b",
+                    "type":"Inner"
+                }
+            ]
+        }"#,
+        )
+        .unwrap();
+
+        let inner_value1 = Value::Record(vec![("z".into(), Value::Int(3))]);
+        let inner_value2 = Value::Record(vec![("z".into(), Value::Int(6))]);
+        let outer = Value::Record(vec![("a".into(), inner_value1), 
("b".into(), inner_value2)]);
+        outer
+            .resolve(&schema)
+            .expect("Record definition defined in one field must be availible 
in other field");
+    }
+
+    #[test]
+    fn test_recursive_resolves2() {
+        let schema = Schema::parse_str(
+            r#"
+        {
+            "type":"record",
+            "name":"TestStruct",
+            "fields": [
+                {
+                    "name":"a",
+                    "type":{
+                        "type":"array",
+                        "items": {
+                            "type":"record",
+                            "name": "Inner",
+                            "fields": [ {
+                                "name":"z",
+                                "type":"int"
+                            }]
+                        }
+                    }
+                },
+                {
+                    "name":"b",
+                    "type": {
+                        "type":"map",
+                        "values":"Inner"
+                    }
+                }
+            ]
+        }"#,
+        )
+        .unwrap();
+
+        let inner_value1 = Value::Record(vec![("z".into(), Value::Int(3))]);
+        let inner_value2 = Value::Record(vec![("z".into(), Value::Int(6))]);
+        let outer_value = Value::Record(vec![
+            ("a".into(), Value::Array(vec![inner_value1])),
+            (
+                "b".into(),
+                Value::Map(vec![("akey".into(), 
inner_value2)].into_iter().collect()),
+            ),
+        ]);
+        outer_value
+            .resolve(&schema)
+            .expect("Record defined in array definition must be resolveable 
from map");
+    }
+
+    #[test]
+    fn test_recursive_resolves3() {
+        let schema = Schema::parse_str(
+            r#"
+        {
+            "type":"record",
+            "name":"TestStruct",
+            "fields": [
+                {
+                    "name":"a",
+                    "type":{
+                        "type":"record",
+                        "name": "Inner",
+                        "fields": [ {
+                            "name":"z",
+                            "type":"int"
+                        }]
+                    }
+                },
+                {
+                    "name":"b",
+                    "type": {
+                        "type":"map",
+                        "values":"Inner"
+                    }
+                }
+            ]
+        }"#,
+        )
+        .unwrap();
+
+        let inner_value1 = Value::Record(vec![("z".into(), Value::Int(3))]);
+        let inner_value2 = Value::Record(vec![("z".into(), Value::Int(6))]);
+        let outer_value = Value::Record(vec![
+            ("a".into(), inner_value1),
+            (
+                "b".into(),
+                Value::Map(vec![("akey".into(), 
inner_value2)].into_iter().collect()),
+            ),
+        ]);
+        outer_value
+            .resolve(&schema)
+            .expect("Record defined in record field must be resolvable from 
map field");
+    }
+
+    #[test]
+    fn test_recursive_resolves4() {
+        let schema = Schema::parse_str(
+            r#"
+        {
+            "type":"record",
+            "name":"TestStruct",
+            "fields": [
+                {
+                    "name":"a",
+                    "type":{
+                        "type":"record",
+                        "name": "Inner",
+                        "fields": [ {
+                            "name":"z",
+                            "type":"int"
+                        }]
+                    }
+                },
+                {
+                    "name":"b",
+                    "type": {
+                        "type":"record",
+                        "name": "InnerWrapper",
+                        "fields": [ {
+                            "name":"j",
+                            "type":"Inner"
+                        }]
+                    }
+                }
+            ]
+        }"#,
+        )
+        .unwrap();
+
+        let inner_value1 = Value::Record(vec![("z".into(), Value::Int(3))]);
+        let inner_value2 = Value::Record(vec![(
+            "j".into(),
+            Value::Record(vec![("z".into(), Value::Int(6))]),
+        )]);
+        let outer_value =
+            Value::Record(vec![("a".into(), inner_value1), ("b".into(), 
inner_value2)]);
+        outer_value.resolve(&schema).expect("Record schema defined in field 
must be resolvable in Record schema defined in other field");
+    }
+
+    #[test]
+    fn test_recursive_resolves5() {
+        let schema = Schema::parse_str(
+            r#"
+        {
+            "type":"record",
+            "name":"TestStruct",
+            "fields": [
+                {
+                    "name":"a",
+                    "type":{
+                        "type":"map",
+                        "values": {
+                            "type":"record",
+                            "name": "Inner",
+                            "fields": [ {
+                                "name":"z",
+                                "type":"int"
+                            }]
+                        }
+                    }
+                },
+                {
+                    "name":"b",
+                    "type": {
+                        "type":"array",
+                        "items":"Inner"
+                    }
+                }
+            ]
+        }"#,
+        )
+        .unwrap();
+
+        let inner_value1 = Value::Record(vec![("z".into(), Value::Int(3))]);
+        let inner_value2 = Value::Record(vec![("z".into(), Value::Int(6))]);
+        let outer_value = Value::Record(vec![
+            (
+                "a".into(),
+                Value::Map(vec![("akey".into(), 
inner_value2)].into_iter().collect()),
+            ),
+            ("b".into(), Value::Array(vec![inner_value1])),
+        ]);
+        outer_value
+            .resolve(&schema)
+            .expect("Record defined in map definition must be resolveable from 
array");
+    }
+
+    #[test]
+    fn test_recursive_resolves6() {
+        let schema = Schema::parse_str(
+            r#"
+        {
+            "type":"record",
+            "name":"TestStruct",
+            "fields": [
+                {
+                    "name":"a",
+                    "type":["null", {
+                        "type":"record",
+                        "name": "Inner",
+                        "fields": [ {
+                            "name":"z",
+                            "type":"int"
+                        }]
+                    }]
+                },
+                {
+                    "name":"b",
+                    "type":"Inner"
+                }
+            ]
+        }"#,
+        )
+        .unwrap();
+
+        let inner_value1 = Value::Record(vec![("z".into(), Value::Int(3))]);
+        let inner_value2 = Value::Record(vec![("z".into(), Value::Int(6))]);
+        let outer1 = Value::Record(vec![
+            ("a".into(), inner_value1),
+            ("b".into(), inner_value2.clone()),
+        ]);
+        outer1
+            .resolve(&schema)
+            .expect("Record definition defined in union must be resolvabled in 
other field");
+        let outer2 = Value::Record(vec![("a".into(), Value::Null), 
("b".into(), inner_value2)]);

Review comment:
       That seems to be working! Thanks again! I'll spend some more time with 
it tomorrow.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 737815)
    Time Spent: 4h 20m  (was: 4h 10m)

> Rust: The canonical form should preserve schema references
> ----------------------------------------------------------
>
>                 Key: AVRO-3433
>                 URL: https://issues.apache.org/jira/browse/AVRO-3433
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: rust
>    Affects Versions: 1.12.0
>            Reporter: Martin Tzvetanov Grigorov
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 4h 20m
>  Remaining Estimate: 0h
>
> Reported at 
> [https://github.com/flavray/avro-rs/issues/182#issuecomment-1059762821]
> =================================
> There still seems to be an issue with {{can't refine}} errors, at least in 
> some non-recursive cases. Take the following example:
> {code:java}
> fn main() {
>     let schema = r#"
>     {
>       "name": "test.test",
>       "type": "record",
>       "fields": [
>         {
>           "name": "bar",
>           "type": { "name": "test.foo", "type": "record", "fields": [{ 
> "name": "id", "type": "long" }] }
>         },
>         { "name": "baz", "type": "test.foo" }
>       ]
>     }
>     "#;
>     let schema = apache_avro::schema::Schema::parse_str(&schema).unwrap();
>     println!("{}", serde_json::to_string(&schema).unwrap());
> } {code}
> This prints the following (the same thing happens if the {{test.foo}} 
> definition is in a separate file):
> {code:java}
> $ target/release/avro-test | jq
> {
>   "type": "record",
>   "name": "test.test",
>   "fields": [
>     {
>       "name": "bar",
>       "type": {
>         "type": "record",
>         "name": "test.foo",
>         "fields": [
>           {
>             "name": "id",
>             "type": "long"
>           }
>         ]
>       }
>     },
>     {
>       "name": "baz",
>       "type": {
>         "type": "record",
>         "name": "test.foo",
>         "fields": [
>           {
>             "name": "id",
>             "type": "long"
>           }
>         ]
>       }
>     }
>   ]
> } {code}
> Which will cause the Java tooling to fail with the 
> {{org.apache.avro.SchemaParseException: Can't redefine: test}} error above.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to