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 2020/02/06 10:06:59 UTC
[avro] branch master updated: AVRO-1646: Print/parse consistency
for nested null namespace (#724)
This is an automated email from the ASF dual-hosted git repository.
rskraba pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 335acc5 AVRO-1646: Print/parse consistency for nested null namespace (#724)
335acc5 is described below
commit 335acc5770f7ad6bd6fdf4caa305373a79912d70
Author: Ben Plommer <be...@gmail.com>
AuthorDate: Thu Feb 6 10:06:48 2020 +0000
AVRO-1646: Print/parse consistency for nested null namespace (#724)
Fixes print-parse consistency for named types with null namespace,
enclosed in named fields with null namespace, which are themselves
enclosed in named fields with non-null namespace.
Currently, if a type specifies the null namespace, this overrides the
enclosing non-null namespace for the purpose of naming that type, but
not for the purposes of determining the closest enclosing namespace for
more deeply nested types. This fixes that by removing special-casing of
null when setting the default namespace for recursively parsed schemas.
Adapted from the patch that was submitted with the AVRO-1646 ticket.
---
lang/java/avro/src/main/java/org/apache/avro/Schema.java | 4 +---
lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java | 10 ++++++++++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
index 65bea4d..ca2bf60 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
@@ -1611,9 +1611,7 @@ public abstract class Schema extends JsonProperties implements Serializable {
if (space == null)
space = names.space();
name = new Name(getRequiredText(schema, "name", "No name in schema"), space);
- if (name.space != null) { // set default namespace
- names.space(name.space);
- }
+ names.space(name.space); // set default namespace
}
if (PRIMITIVES.containsKey(type)) { // primitive
result = create(PRIMITIVES.get(type));
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java b/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
index a639117..0614af2 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
@@ -448,6 +448,16 @@ public class TestSchema {
}
@Test
+ public void testDeeplyNestedNullNamespace() {
+ Schema inner = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":["
+ + "{\"name\":\"x\",\"type\":{\"type\":\"record\",\"name\":\"Deeper\",\"fields\":["
+ + "{\"name\":\"y\",\"type\":\"int\"}]}}]}");
+ Schema outer = Schema.createRecord("Outer", null, "space", false);
+ outer.setFields(Collections.singletonList(new Field("f", inner, null, null)));
+ assertEquals(outer, new Schema.Parser().parse(outer.toString()));
+ }
+
+ @Test
public void testNestedNullNamespaceReferencing() {
Schema inner = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":[]}");
Schema outer = Schema.createRecord("Outer", null, "space", false);