You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/11/18 13:34:24 UTC

[avro] branch avro-3674-cleanup created (now fc75608f7)

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a change to branch avro-3674-cleanup
in repository https://gitbox.apache.org/repos/asf/avro.git


      at fc75608f7 AVRO-3674: Code cleanup

This branch includes the following new commits:

     new fc75608f7 AVRO-3674: Code cleanup

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[avro] 01/01: AVRO-3674: Code cleanup

Posted by mg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch avro-3674-cleanup
in repository https://gitbox.apache.org/repos/asf/avro.git

commit fc75608f79424faf0b3e08fdc67f8d2a2cafa431
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Fri Nov 18 15:33:24 2022 +0200

    AVRO-3674: Code cleanup
    
    Remove obsolete FIXME.
    Remove wrong comments.
    Remove duplicate code.
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
 lang/rust/avro/src/types.rs | 99 +++++++++------------------------------------
 1 file changed, 19 insertions(+), 80 deletions(-)

diff --git a/lang/rust/avro/src/types.rs b/lang/rust/avro/src/types.rs
index 5442a2c36..9f4193db0 100644
--- a/lang/rust/avro/src/types.rs
+++ b/lang/rust/avro/src/types.rs
@@ -564,7 +564,6 @@ impl Value {
     /// resolution.
     pub fn resolve(self, schema: &Schema) -> AvroResult<Self> {
         let enclosing_namespace = schema.namespace();
-        // FIXME transition to using resolved Schema
         let rs = ResolvedSchema::try_from(schema)?;
         self.resolve_internal(schema, rs.get_names(), &enclosing_namespace)
     }
@@ -2432,27 +2431,25 @@ Field with name '"b"' is not a member of the map items"#,
         assert!(
             !test_outer1.validate(&schema),
             "field b record is invalid against the schema"
-        ); // this should pass, but doesn't
+        );
         assert!(
             !test_outer2.validate(&schema),
             "field b record is invalid against the schema"
-        ); // this should pass, but doesn't
+        );
         assert!(
             !test_outer3.validate(&schema),
             "field b record is invalid against the schema"
-        ); // this should pass, but doesn't
+        );
     }
 
-    #[test]
-    fn test_avro_3674_validate_namespace_resolution() {
+    fn avro_3674_with_or_without_namespace(with_namespace: bool) {
         use crate::ser::Serializer;
         use serde::Serialize;
 
-        let schema = Schema::parse_str(
-            r#"{
+        let schema_str = r#"{
             "type": "record",
             "name": "NamespacedMessage",
-            "namespace": "com.domain",
+            [NAMESPACE]
             "fields": [
                 {
                     "type": "record",
@@ -2477,9 +2474,14 @@ Field with name '"b"' is not a member of the map items"#,
                     ]
                 }
             ]
-        }"#,
-        )
-        .unwrap();
+        }"#;
+        let schema_str = schema_str.replace("[NAMESPACE]", if with_namespace {
+            r#""namespace": "com.domain","#
+        } else {
+            ""
+        });
+
+        let schema = Schema::parse_str(&schema_str).unwrap();
 
         #[derive(Serialize)]
         enum EnumType {
@@ -2518,74 +2520,11 @@ Field with name '"b"' is not a member of the map items"#,
 
     #[test]
     fn test_avro_3674_validate_no_namespace_resolution() {
-        use crate::ser::Serializer;
-        use serde::Serialize;
-
-        let schema = Schema::parse_str(
-            r#"{
-            "type": "record",
-            "name": "NoNamespacedMessage",
-            "fields": [
-                {
-                    "type": "record",
-                    "name": "field_a",
-                    "fields": [
-                        {
-                            "name": "enum_a",
-                            "type": {
-                                "type": "enum",
-                                "name": "EnumType",
-                                "symbols": [
-                                    "SYMBOL_1",
-                                    "SYMBOL_2"
-                                ],
-                                "default": "SYMBOL_1"
-                            }
-                        },
-                        {
-                            "name": "enum_b",
-                            "type": "EnumType"
-                        }
-                    ]
-                }
-            ]
-        }"#,
-        )
-        .unwrap();
-
-        #[derive(Serialize)]
-        enum EnumType {
-            #[serde(rename = "SYMBOL_1")]
-            Symbol1,
-            #[serde(rename = "SYMBOL_2")]
-            Symbol2,
-        }
-
-        #[derive(Serialize)]
-        struct FieldA {
-            enum_a: EnumType,
-            enum_b: EnumType,
-        }
-
-        #[derive(Serialize)]
-        struct NamespacedMessage {
-            field_a: FieldA,
-        }
-
-        let msg = NamespacedMessage {
-            field_a: FieldA {
-                enum_a: EnumType::Symbol2,
-                enum_b: EnumType::Symbol1,
-            },
-        };
+        avro_3674_with_or_without_namespace(false);
+    }
 
-        let mut ser = Serializer::default();
-        let test_value: Value = msg.serialize(&mut ser).unwrap();
-        let resolved = test_value.resolve(&schema);
-        assert!(resolved.is_ok(), "test_value should resolve");
-        assert!(
-            resolved.unwrap().validate(&schema),
-            "test_value should validate"
-        );
+    #[test]
+    fn test_avro_3674_validate_with_namespace_resolution() {
+        avro_3674_with_or_without_namespace(true);
     }
 }