[1/4] flink git commit: [FLINK-2447] [java api] TypeExtractor returns wrong type info when a Tuple has two fields of the same POJO type

2015-08-05 Thread fhueske
Repository: flink
Updated Branches:
  refs/heads/master 941ac6dfd - fb7e63422


[FLINK-2447] [java api] TypeExtractor returns wrong type info when a Tuple has 
two fields of the same POJO type

This closes #986


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/5546a1ef
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/5546a1ef
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/5546a1ef

Branch: refs/heads/master
Commit: 5546a1efabcc9c5f500abdb4e38a5cc05d35980a
Parents: 941ac6d
Author: twalthr twal...@apache.org
Authored: Tue Aug 4 15:30:28 2015 +0200
Committer: Fabian Hueske fhue...@apache.org
Committed: Wed Aug 5 12:00:56 2015 +0200

--
 .../flink/api/java/typeutils/TypeExtractor.java | 53 
 .../type/extractor/PojoTypeExtractionTest.java  | 63 
 2 files changed, 104 insertions(+), 12 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/flink/blob/5546a1ef/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
--
diff --git 
a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
 
b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
index 41644f9..1ae8d3d 100644
--- 
a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
+++ 
b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
@@ -26,9 +26,7 @@ import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.avro.specific.SpecificRecordBase;
 import org.apache.flink.api.common.functions.CoGroupFunction;
@@ -66,15 +64,33 @@ import com.google.common.base.Preconditions;
  * functions.
  */
 public class TypeExtractor {
+
+   /*
+* NOTE: Most methods of the TypeExtractor work with a so-called 
typeHierarchy.
+* The type hierarchy describes all types (Classes, ParameterizedTypes, 
TypeVariables etc. ) and intermediate
+* types from a given type of a function or type (e.g. MyMapper, 
Tuple2) until a current type
+* (depends on the method, e.g. MyPojoFieldType).
+*
+* Thus, it fully qualifies types until tuple/POJO field level.
+*
+* A typical typeHierarchy could look like:
+*
+* UDF: MyMapFunction.class
+* top-level UDF: MyMapFunctionBase.class
+* RichMapFunction: RichMapFunction.class
+* MapFunction: MapFunction.class
+* Function's OUT: Tuple1MyPojo
+* user-defined POJO: MyPojo.class
+* user-defined top-level POJO: MyPojoBase.class
+* POJO field: Tuple1String
+* Field type: String.class
+*
+*/

private static final Logger LOG = 
LoggerFactory.getLogger(TypeExtractor.class);
 
-   // We need this to detect recursive types and not get caught
-   // in an endless recursion
-   private SetClass? alreadySeen;
-
protected TypeExtractor() {
-   alreadySeen = new HashSetClass?();
+   // only create instances for special use cases
}
 
// 

@@ -416,10 +432,12 @@ public class TypeExtractor {

TypeInformation?[] tupleSubTypes = new 
TypeInformation?[subtypes.length];
for (int i = 0; i  subtypes.length; i++) {
+   ArrayListType subTypeHierarchy = new 
ArrayListType(typeHierarchy);
+   subTypeHierarchy.add(subtypes[i]);
// sub type could not be determined with 
materializing
// try to derive the type info of the 
TypeVariable from the immediate base child input as a last attempt
if (subtypes[i] instanceof TypeVariable?) {
-   tupleSubTypes[i] = 
createTypeInfoFromInputs((TypeVariable?) subtypes[i], typeHierarchy, in1Type, 
in2Type);
+   tupleSubTypes[i] = 
createTypeInfoFromInputs((TypeVariable?) subtypes[i], subTypeHierarchy, 
in1Type, in2Type);

// variable could not be determined
if (tupleSubTypes[i] == null) {
@@ -430,7 +448,7 @@ public class TypeExtractor {
+ all 
variables in the return type can be deduced from the input type(s).);
  

flink git commit: [FLINK-2447] [java api] TypeExtractor returns wrong type info when a Tuple has two fields of the same POJO type

2015-08-05 Thread fhueske
Repository: flink
Updated Branches:
  refs/heads/release-0.9 80d3478c0 - ec3b98327


[FLINK-2447] [java api] TypeExtractor returns wrong type info when a Tuple has 
two fields of the same POJO type


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/ec3b9832
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/ec3b9832
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/ec3b9832

Branch: refs/heads/release-0.9
Commit: ec3b983276e85e0baed98ffa8acf6709f20032de
Parents: 80d3478
Author: twalthr twal...@apache.org
Authored: Tue Aug 4 15:30:28 2015 +0200
Committer: Fabian Hueske fhue...@apache.org
Committed: Wed Aug 5 16:25:32 2015 +0200

--
 .../flink/api/java/typeutils/TypeExtractor.java | 53 
 .../type/extractor/PojoTypeExtractionTest.java  | 63 
 2 files changed, 104 insertions(+), 12 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/flink/blob/ec3b9832/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
--
diff --git 
a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
 
b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
index 41644f9..1ae8d3d 100644
--- 
a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
+++ 
b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
@@ -26,9 +26,7 @@ import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.avro.specific.SpecificRecordBase;
 import org.apache.flink.api.common.functions.CoGroupFunction;
@@ -66,15 +64,33 @@ import com.google.common.base.Preconditions;
  * functions.
  */
 public class TypeExtractor {
+
+   /*
+* NOTE: Most methods of the TypeExtractor work with a so-called 
typeHierarchy.
+* The type hierarchy describes all types (Classes, ParameterizedTypes, 
TypeVariables etc. ) and intermediate
+* types from a given type of a function or type (e.g. MyMapper, 
Tuple2) until a current type
+* (depends on the method, e.g. MyPojoFieldType).
+*
+* Thus, it fully qualifies types until tuple/POJO field level.
+*
+* A typical typeHierarchy could look like:
+*
+* UDF: MyMapFunction.class
+* top-level UDF: MyMapFunctionBase.class
+* RichMapFunction: RichMapFunction.class
+* MapFunction: MapFunction.class
+* Function's OUT: Tuple1MyPojo
+* user-defined POJO: MyPojo.class
+* user-defined top-level POJO: MyPojoBase.class
+* POJO field: Tuple1String
+* Field type: String.class
+*
+*/

private static final Logger LOG = 
LoggerFactory.getLogger(TypeExtractor.class);
 
-   // We need this to detect recursive types and not get caught
-   // in an endless recursion
-   private SetClass? alreadySeen;
-
protected TypeExtractor() {
-   alreadySeen = new HashSetClass?();
+   // only create instances for special use cases
}
 
// 

@@ -416,10 +432,12 @@ public class TypeExtractor {

TypeInformation?[] tupleSubTypes = new 
TypeInformation?[subtypes.length];
for (int i = 0; i  subtypes.length; i++) {
+   ArrayListType subTypeHierarchy = new 
ArrayListType(typeHierarchy);
+   subTypeHierarchy.add(subtypes[i]);
// sub type could not be determined with 
materializing
// try to derive the type info of the 
TypeVariable from the immediate base child input as a last attempt
if (subtypes[i] instanceof TypeVariable?) {
-   tupleSubTypes[i] = 
createTypeInfoFromInputs((TypeVariable?) subtypes[i], typeHierarchy, in1Type, 
in2Type);
+   tupleSubTypes[i] = 
createTypeInfoFromInputs((TypeVariable?) subtypes[i], subTypeHierarchy, 
in1Type, in2Type);

// variable could not be determined
if (tupleSubTypes[i] == null) {
@@ -430,7 +448,7 @@ public class TypeExtractor {
+ all 
variables in the return type can be deduced from the input type(s).);