Author: cutting
Date: Tue Jul 1 21:18:11 2014
New Revision: 1607189
URL: http://svn.apache.org/r1607189
Log:
AVRO-1535. Java: Make the name .X to refer to X in the null namespace.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/doc/src/content/xdocs/spec.xml
avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java
avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
Modified: avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1607189&r1=1607188&r2=1607189&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Jul 1 21:18:11 2014
@@ -54,6 +54,9 @@ Trunk (not yet released)
AVRO-1512. Java: Support Thrift unions. (cutting)
+ AVRO-1535. Java: Make the name .X to refer to X in the null namespace.
+ This permits aliases to names in the null namespace. (cutting)
+
BUG FIXES
AVRO-1446. C#: Correctly handle system errors in RPC.
Modified: avro/trunk/doc/src/content/xdocs/spec.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/doc/src/content/xdocs/spec.xml?rev=1607189&r1=1607188&r2=1607189&view=diff
==============================================================================
--- avro/trunk/doc/src/content/xdocs/spec.xml (original)
+++ avro/trunk/doc/src/content/xdocs/spec.xml Tue Jul 1 21:18:11 2014
@@ -259,6 +259,8 @@
<li>subsequently contain only <code>[A-Za-z0-9_]</code></li>
</ul>
<p>A namespace is a dot-separated sequence of such names.
+ The empty string may also be used as a namespace to indicate the
+ null namespace.
Equality of names (including field names and enum symbols)
as well as fullnames is case-sensitive.</p>
<p>In record, enum and fixed definitions, the fullname is
@@ -279,7 +281,8 @@
if <code>"name": "X"</code> is specified, and this occurs
within a field of the record definition
of <code>org.foo.Y</code>, then the fullname
- is <code>org.foo.X</code>.</li>
+ is <code>org.foo.X</code>. If there is no enclosing
+ namespace then the null namespace is used.</li>
</ul>
<p>References to previously defined names are as in the latter
two cases above: if they contain a dot they are a fullname, if
Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java?rev=1607189&r1=1607188&r2=1607189&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java Tue Jul
1 21:18:11 2014
@@ -432,15 +432,15 @@ public abstract class Schema extends Jso
return;
}
int lastDot = name.lastIndexOf('.');
- if ("".equals(space))
- space = null;
if (lastDot < 0) { // unqualified name
- this.space = space; // use default space
this.name = validateName(name);
} else { // qualified name
- this.space = name.substring(0, lastDot); // get space from name
+ space = name.substring(0, lastDot); // get space from name
this.name = validateName(name.substring(lastDot+1, name.length()));
}
+ if ("".equals(space))
+ space = null;
+ this.space = space;
this.full = (this.space == null) ? this.name : this.space+"."+this.name;
}
public boolean equals(Object o) {
Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java?rev=1607189&r1=1607188&r2=1607189&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
(original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java Tue
Jul 1 21:18:11 2014
@@ -526,6 +526,17 @@ public class TestSchema {
}
@Test
+ public void testNullNamespaceAlias() throws Exception {
+ Schema s =
+ Schema.parse("{\"type\":\"record\",\"name\":\"Z\",\"fields\":[]}");
+ Schema t =
+
Schema.parse("{\"type\":\"record\",\"name\":\"x.Y\",\"aliases\":[\".Z\"],"
+ +"\"fields\":[]}");
+ Schema u = Schema.applyAliases(s, t);
+ assertEquals("x.Y", u.getFullName());
+ }
+
+ @Test
public void testNullPointer() throws Exception {
String recordJson = "{\"type\":\"record\", \"name\":\"Test\", \"fields\":"
+"[{\"name\":\"x\", \"type\":\"string\"}]}";