You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2017/12/18 18:02:28 UTC
[1/4] avro git commit: AVRO-2115: Control commit.
Repository: avro
Updated Branches:
refs/heads/master ff5099c85 -> 5040c6413
AVRO-2115: Control commit.
Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/c412267d
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/c412267d
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/c412267d
Branch: refs/heads/master
Commit: c412267d1d32ab10a929f189cb53cfb3cc619300
Parents: 7bbbf92
Author: Miguel Martinez-Espronceda <co...@i2p.es>
Authored: Wed Dec 13 11:19:15 2017 +0100
Committer: Miguel Martinez-Espronceda <co...@i2p.es>
Committed: Wed Dec 13 12:04:08 2017 +0100
----------------------------------------------------------------------
.../org/apache/avro/reflect/ReflectData.java | 4 ++++
.../java/org/apache/avro/reflect/Union.java | 2 +-
.../org/apache/avro/reflect/TestReflect.java | 25 ++++++++++++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/avro/blob/c412267d/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
index eb9f5fb..7220813 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
@@ -744,6 +744,10 @@ public class ReflectData extends SpecificData {
if (explicit != null) // explicit schema
return Schema.parse(explicit.value());
+ Union union = field.getAnnotation(Union.class);
+ if (union != null)
+ return getAnnotatedUnion(union, names);
+
Schema schema = createSchema(field.getGenericType(), names);
if (field.isAnnotationPresent(Stringable.class)) { // Stringable
schema = Schema.create(Schema.Type.STRING);
http://git-wip-us.apache.org/repos/asf/avro/blob/c412267d/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
index b22fa66..d823ebc 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
@@ -31,7 +31,7 @@ import java.lang.annotation.Target;
* to a method, this determines its return type.
*/
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.PARAMETER, ElementType.METHOD})
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Documented
public @interface Union {
/** The instantiable classes that compose this union. */
http://git-wip-us.apache.org/repos/asf/avro/blob/c412267d/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
index afe7f08..4d8a388 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
@@ -297,6 +297,31 @@ public class TestReflect {
checkReadWrite(r9, ReflectData.get().getSchema(R9.class));
}
+ // test union in fields
+ public static class R9_1 {
+ @Union({R7.class, R8.class})
+ public Object value;
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof R9_1)) return false;
+ return this.value.equals(((R9_1)o).value);
+ }
+ }
+
+ @Test public void testR6_1() throws Exception {
+ R7 r7 = new R7();
+ r7.value = 1;
+ checkReadWrite(r7, ReflectData.get().getSchema(R6.class));
+ R8 r8 = new R8();
+ r8.value = 1;
+ checkReadWrite(r8, ReflectData.get().getSchema(R6.class));
+ R9_1 r9_1 = new R9_1();
+ r9_1.value = r7;
+ checkReadWrite(r9_1, ReflectData.get().getSchema(R9_1.class));
+ r9_1.value = r8;
+ checkReadWrite(r9_1, ReflectData.get().getSchema(R9_1.class));
+ }
+
// test union annotation on methods and parameters
public static interface P0 {
@Union({Void.class,String.class})
[4/4] avro git commit: AVRO-2115: Java: Permit @Union annotations on
fields of classes.
Posted by cu...@apache.org.
AVRO-2115: Java: Permit @Union annotations on fields of classes.
Contributed by Miguel Martinez-Espronceda.
Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/5040c641
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/5040c641
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/5040c641
Branch: refs/heads/master
Commit: 5040c6413b112665cd051c415f368f9a51426b97
Parents: ff5099c 53a9af7
Author: Doug Cutting <cu...@apache.org>
Authored: Mon Dec 18 10:01:47 2017 -0800
Committer: Doug Cutting <cu...@apache.org>
Committed: Mon Dec 18 10:01:47 2017 -0800
----------------------------------------------------------------------
CHANGES.txt | 4 +++
.../org/apache/avro/reflect/ReflectData.java | 4 +++
.../java/org/apache/avro/reflect/Union.java | 5 ++--
.../java/org/apache/avro/reflect/package.html | 2 +-
.../org/apache/avro/reflect/TestReflect.java | 28 ++++++++++++++++++++
5 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/avro/blob/5040c641/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index d23a5bb,a621c65..008e230
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -3,6 -3,6 +3,7 @@@ Avro Change Lo
Trunk (not yet released)
INCOMPATIBLE CHANGES
++
AVRO-2003: Report specific location of schema incompatibilities (teabot via nkollar)
AVRO-2035: Java: validate default values when parsing schemas. (cutting)
@@@ -90,15 -90,6 +91,18 @@@
AVRO-2055: Remove Magic Value From org.apache.avro.hadoop.io.AvroSequenceFile
(Beluga Behr via gabor)
+ AVRO-1047: Remaining warnings in generated Java code exposed by -Xlint:all fixed.
+ (Michael Werle via Niels Basjes)
+
+ AVRO-2080: Fix Javadoc Warnings in Generated Records
+ (Bridger Howell via Niels Basjes)
+
+ AVRO-2114: Make missing value exceptions in nested structures easier to read.
+ (Niels Basjes)
+
++ AVRO-2115: Java: Permit @Union annotations on fields of classes.
++ (Miguel Martinez-Espronceda via cutting).
++
BUG FIXES
AVRO-1741: Python3: Fix error when codec is not in the header.
http://git-wip-us.apache.org/repos/asf/avro/blob/5040c641/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
----------------------------------------------------------------------
diff --cc lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
index b22fa66,8f9f276..e192ffa
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
@@@ -28,10 -28,11 +28,11 @@@ import java.lang.annotation.Target
* May be used for base classes or interfaces whose instantiable subclasses can
* be listed in the parameters to the @Union annotation. If applied to method
* parameters this determines the reflected message parameter type. If applied
- * to a method, this determines its return type.
- * to a method, this determines its return type. A null schema may be specified
++ * to a method, this determines its return type. A null schema may be specified
+ * with {@link java.lang.Void}.
*/
@Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.TYPE, ElementType.PARAMETER, ElementType.METHOD})
+ @Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Documented
public @interface Union {
/** The instantiable classes that compose this union. */
[3/4] avro git commit: AVRO-2115: Added documentation.
Posted by cu...@apache.org.
AVRO-2115: Added documentation.
Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/53a9af76
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/53a9af76
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/53a9af76
Branch: refs/heads/master
Commit: 53a9af762acbfdc734a3cadf7d3c6d8736e1ec61
Parents: 164ee58
Author: Miguel Martinez-Espronceda <co...@i2p.es>
Authored: Fri Dec 15 09:39:13 2017 +0100
Committer: Miguel Martinez-Espronceda <co...@i2p.es>
Committed: Fri Dec 15 09:39:13 2017 +0100
----------------------------------------------------------------------
lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java | 3 ++-
lang/java/avro/src/main/java/org/apache/avro/reflect/package.html | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/avro/blob/53a9af76/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
index d823ebc..8f9f276 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/Union.java
@@ -28,7 +28,8 @@ import java.lang.annotation.Target;
* May be used for base classes or interfaces whose instantiable subclasses can
* be listed in the parameters to the @Union annotation. If applied to method
* parameters this determines the reflected message parameter type. If applied
- * to a method, this determines its return type.
+ * to a method, this determines its return type. A null schema may be specified
+ * with {@link java.lang.Void}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
http://git-wip-us.apache.org/repos/asf/avro/blob/53a9af76/lang/java/avro/src/main/java/org/apache/avro/reflect/package.html
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/package.html b/lang/java/avro/src/main/java/org/apache/avro/reflect/package.html
index dc6dbb9..98eca3f 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/package.html
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/package.html
@@ -30,7 +30,7 @@ classes.
that are not static or transient are used. Fields are not permitted
to be null unless annotated by {@link
org.apache.avro.reflect.Nullable Nullable} or a {@link
- org.apache.avro.reflect.Union Union} containing null.</li>
+ org.apache.avro.reflect.Union Union} containing {@link java.lang.Void}.</li>
<li><b>Arrays</b> are mapped to Avro array schemas. If an array's
elements are a union defined by the {@link
[2/4] avro git commit: AVRO-2115: Added test for Void in union.
Posted by cu...@apache.org.
AVRO-2115: Added test for Void in union.
Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/164ee588
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/164ee588
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/164ee588
Branch: refs/heads/master
Commit: 164ee588cf822588df2c877f07ba03cb1a4a9482
Parents: c412267
Author: Miguel Martinez-Espronceda <co...@i2p.es>
Authored: Thu Dec 14 10:12:47 2017 +0100
Committer: Miguel Martinez-Espronceda <co...@i2p.es>
Committed: Thu Dec 14 10:12:47 2017 +0100
----------------------------------------------------------------------
.../avro/src/test/java/org/apache/avro/reflect/TestReflect.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/avro/blob/164ee588/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
index 4d8a388..51ce7c2 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
@@ -299,11 +299,12 @@ public class TestReflect {
// test union in fields
public static class R9_1 {
- @Union({R7.class, R8.class})
+ @Union({Void.class, R7.class, R8.class})
public Object value;
@Override
public boolean equals(Object o) {
if (!(o instanceof R9_1)) return false;
+ if (this.value == null) return ((R9_1)o).value == null;
return this.value.equals(((R9_1)o).value);
}
}
@@ -316,6 +317,8 @@ public class TestReflect {
r8.value = 1;
checkReadWrite(r8, ReflectData.get().getSchema(R6.class));
R9_1 r9_1 = new R9_1();
+ r9_1.value = null;
+ checkReadWrite(r9_1, ReflectData.get().getSchema(R9_1.class));
r9_1.value = r7;
checkReadWrite(r9_1, ReflectData.get().getSchema(R9_1.class));
r9_1.value = r8;