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]