You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by rs...@apache.org on 2022/03/08 18:36:29 UTC

[avro] branch branch-1.11 updated (23a1c88 -> 6980d52)

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

rskraba pushed a change to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git.


    from 23a1c88  AVRO-3437: Rust: Update dependencies (#1585)
     new 0de8c6e  AVRO-3370: Clarify spec with regards to permitted names (#1573)
     new 6980d52  AVRO-3370: Allow complex types as names (#1533)

The 2 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.


Summary of changes:
 doc/content/en/docs/next/Specification/_index.md |  5 +++--
 lang/py/avro/name.py                             |  4 ++--
 lang/py/avro/test/test_io.py                     |  8 ++++++++
 lang/py/avro/test/test_schema.py                 | 14 ++++++++++++++
 4 files changed, 27 insertions(+), 4 deletions(-)

[avro] 01/02: AVRO-3370: Clarify spec with regards to permitted names (#1573)

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

rskraba pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 0de8c6e2b1cde3da9bb03ab15747001408559f93
Author: Ryan Skraba <ry...@skraba.com>
AuthorDate: Tue Mar 8 19:33:07 2022 +0100

    AVRO-3370: Clarify spec with regards to permitted names (#1573)
    
    * AVRO-3370: Clarify spec with regards to permitted names
    
    * Suggestion when to use a namespace
---
 doc/content/en/docs/next/Specification/_index.md | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/doc/content/en/docs/next/Specification/_index.md b/doc/content/en/docs/next/Specification/_index.md
index a1fa191..49e030d 100755
--- a/doc/content/en/docs/next/Specification/_index.md
+++ b/doc/content/en/docs/next/Specification/_index.md
@@ -1,4 +1,3 @@
-
 ---
 title: "Specification"
 linkTitle: "Specification"
@@ -251,7 +250,9 @@ The fullname of a record, enum or fixed definition is determined by the required
 
 References to previously defined names are as in the latter two cases above: if they contain a dot they are a fullname, if they do not contain a dot, the namespace is the namespace of the enclosing definition.
 
-Primitive type names have no namespace and their names may not be defined in any namespace.
+Primitive type names (`null`, `boolean`, `int`, `long`, `float`, `double`, `bytes`, `string`) have no namespace and their names may not be defined in any namespace.
+
+Complex types (`record`, `enum`, `array`, `map`, `fixed`) have no namespace, but their names (as well as `union`) are permitted to be reused as type names.  This can be confusing to the human reader, but is always unambiguous for binary serialization.  Due to the limitations of JSON encoding, it is a best practice to use a namespace when using these names.
 
 A schema or protocol may not contain multiple definitions of a fullname. Further, a name must be defined before it is used ("before" in the depth-first, left-to-right traversal of the JSON parse tree, where the types attribute of a protocol is always deemed to come "before" the messages attribute.)
 

[avro] 02/02: AVRO-3370: Allow complex types as names (#1533)

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

rskraba pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 6980d52cbe290ecdaa72d22902a1ca8e61c560ce
Author: Ryan Skraba <ry...@skraba.com>
AuthorDate: Tue Mar 8 19:34:55 2022 +0100

    AVRO-3370: Allow complex types as names (#1533)
---
 lang/py/avro/name.py             |  4 ++--
 lang/py/avro/test/test_io.py     |  8 ++++++++
 lang/py/avro/test/test_schema.py | 14 ++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lang/py/avro/name.py b/lang/py/avro/name.py
index 0ea6974..67f1e0f 100644
--- a/lang/py/avro/name.py
+++ b/lang/py/avro/name.py
@@ -20,7 +20,7 @@
 """Contains the Name classes."""
 from typing import TYPE_CHECKING, Dict, Optional
 
-from avro.constants import VALID_TYPES
+from avro.constants import PRIMITIVE_TYPES
 
 if TYPE_CHECKING:
     from avro.schema import NamedSchema
@@ -154,7 +154,7 @@ class Names:
         """
         to_add = Name(name_attr, space_attr, self.default_namespace)
 
-        if to_add.fullname in VALID_TYPES:
+        if to_add.fullname in PRIMITIVE_TYPES:
             raise avro.errors.SchemaParseException(f"{to_add.fullname} is a reserved type name.")
         if to_add.fullname in self.names:
             raise avro.errors.SchemaParseException(f'The name "{to_add.fullname}" is already in use.')
diff --git a/lang/py/avro/test/test_io.py b/lang/py/avro/test/test_io.py
index 99f9aa5..6ca3a61 100644
--- a/lang/py/avro/test/test_io.py
+++ b/lang/py/avro/test/test_io.py
@@ -163,6 +163,14 @@ SCHEMAS_TO_VALIDATE = tuple(
             },
             {"value": {"car": {"value": "head"}, "cdr": {"value": None}}},
         ),
+        (
+            {"type": "record", "name": "record", "fields": [{"name": "value", "type": "int"}, {"name": "next", "type": ["null", "record"]}]},
+            {"value": 0, "next": {"value": 1, "next": None}},
+        ),
+        (
+            {"type": "record", "name": "ns.long", "fields": [{"name": "value", "type": "int"}, {"name": "next", "type": ["null", "ns.long"]}]},
+            {"value": 0, "next": {"value": 1, "next": None}},
+        ),
     )
 )
 
diff --git a/lang/py/avro/test/test_schema.py b/lang/py/avro/test/test_schema.py
index b5906d2..ed10163 100644
--- a/lang/py/avro/test/test_schema.py
+++ b/lang/py/avro/test/test_schema.py
@@ -120,6 +120,19 @@ UNION_EXAMPLES = [
     InvalidTestSchema([{"type": "array", "items": "long"}, {"type": "array", "items": "string"}]),
 ]
 
+NAME_EXAMPLES = [
+    ValidTestSchema({"type": "enum", "name": "record", "symbols": ["A", "B"]}),
+    ValidTestSchema({"type": "record", "name": "record", "fields": [{"name": "f", "type": "long"}]}),
+    InvalidTestSchema({"type": "enum", "name": "int", "symbols": ["A", "B"]}),
+    ValidTestSchema({"type": "enum", "name": "ns.int", "symbols": ["A", "B"]}),
+    ValidTestSchema({"type": "enum", "namespace": "ns", "name": "int", "symbols": ["A", "B"]}),
+    ValidTestSchema(
+        {"type": "record", "name": "LinkedList", "fields": [{"name": "value", "type": "int"}, {"name": "next", "type": ["null", "LinkedList"]}]}
+    ),
+    ValidTestSchema({"type": "record", "name": "record", "fields": [{"name": "value", "type": "int"}, {"name": "next", "type": ["null", "record"]}]}),
+    ValidTestSchema({"type": "record", "name": "ns.int", "fields": [{"name": "value", "type": "int"}, {"name": "next", "type": ["null", "ns.int"]}]}),
+]
+
 NAMED_IN_UNION_EXAMPLES = [
     ValidTestSchema(
         {
@@ -512,6 +525,7 @@ EXAMPLES += ENUM_EXAMPLES
 EXAMPLES += ARRAY_EXAMPLES
 EXAMPLES += MAP_EXAMPLES
 EXAMPLES += UNION_EXAMPLES
+EXAMPLES += NAME_EXAMPLES
 EXAMPLES += NAMED_IN_UNION_EXAMPLES
 EXAMPLES += RECORD_EXAMPLES
 EXAMPLES += DOC_EXAMPLES