You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/11/11 12:10:12 UTC

[GitHub] [avro] martin-g commented on a diff in pull request #1949: AVRO-3646: integration tests for (de)serializing of enum with mixed variants

martin-g commented on code in PR #1949:
URL: https://github.com/apache/avro/pull/1949#discussion_r1020163782


##########
lang/rust/avro/tests/serde_enum_with_duplicates.rs:
##########
@@ -0,0 +1,279 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use apache_avro::{from_value, to_value, types::Value, Schema};
+use pretty_assertions::assert_eq;
+use serde::{Deserialize, Serialize};
+
+const SCHEMA_STR: &str = r#"
+        {
+            "type": "record",
+            "name": "serde_enum",
+            "fields": [
+                {
+                    "name": "a",
+                    "type": {
+                        "type": "record",
+                        "name": "TestEnum",
+                        "fields": [
+                            {
+                                "name": "type",
+                                "type": {
+                                    "type": "enum",
+                                    "name": "TestEnumType",
+                                    "symbols": [
+                                        "NullVariant1",
+                                        "NullVariant2",
+                                        "NullTupleVariant",
+                                        "NullNewTypeVariant",
+                                        "NullStructVariant",
+                                        "IntVariant1",
+                                        "IntVariant2",
+                                        "TupleVariant",
+                                        "StructVariant",
+                                        "NameStructVariant"
+                                    ]
+                                }
+                            },
+                            {
+                                "name": "value",
+                                "type": [
+                                    "null",
+                                    "long",
+                                    {
+                                        "type": "array",
+                                        "items": "long"
+                                    },
+                                    {
+                                        "type": "record",
+                                        "name": "StructVariant",
+                                        "fields": [
+                                            {
+                                                "name": "b",
+                                                "type": "long"
+                                            }
+                                        ]
+                                    }
+                                ]
+                            }
+                        ]
+                    }
+                }
+            ]
+        }
+        "#;
+
+#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
+struct TestExternalEnum {
+    a: TestEnum,
+}
+
+#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
+struct TestStruct {
+    b: i64,
+}
+
+#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
+enum TestEnum {
+    NullVariant1,
+    NullVariant2,

Review Comment:
   Both `NullVariant1` and `NullVariant2` are serialized to `Value::Null`.
   According to the Avro [specification](https://avro.apache.org/docs/1.11.1/specification/#unions) there could be one value of a given type in an union: 
   ```
   Unions may not contain more than one schema with the same type, except for the named types record, fixed and enum.
   ```
   So, it is not possible to have two `null` variants, no matter whether they are unit, tuple, newtype or struct.



-- 
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: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org