flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject incubator-flink git commit: Small changes and tests for the newly introduced EnumType
Date Tue, 25 Nov 2014 19:01:36 GMT
Repository: incubator-flink
Updated Branches:
  refs/heads/master 65d85f10c -> 8724bf7c8


Small changes and tests for the newly introduced EnumType

This closes #230.


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

Branch: refs/heads/master
Commit: 8724bf7c8ae2a99a1f3b5d835840abe4c5da9507
Parents: 65d85f1
Author: twalthr <info@twalthr.com>
Authored: Tue Nov 25 11:51:10 2014 +0100
Committer: Ufuk Celebi <uce@apache.org>
Committed: Tue Nov 25 20:00:47 2014 +0100

----------------------------------------------------------------------
 .../flink/api/java/typeutils/EnumTypeInfo.java  |  1 -
 .../flink/api/java/typeutils/TypeExtractor.java | 16 ++++++++++++--
 .../java/type/extractor/TypeExtractorTest.java  | 22 ++++++++++++++++++++
 3 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/8724bf7c/flink-java/src/main/java/org/apache/flink/api/java/typeutils/EnumTypeInfo.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/EnumTypeInfo.java
b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/EnumTypeInfo.java
index 8bf8a66..c2a0b7f 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/EnumTypeInfo.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/EnumTypeInfo.java
@@ -39,7 +39,6 @@ public class EnumTypeInfo<T extends Enum<T>> extends TypeInformation<T>
implemen
 		this.typeClass = typeClass;
 	}
 
-	@SuppressWarnings({ "rawtypes", "unchecked" })
 	@Override
 	public TypeComparator<T> createComparator(boolean sortOrderAscending) {
 		return new EnumComparator<T>(sortOrderAscending);

http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/8724bf7c/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 55faff1..67b2a51 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
@@ -721,6 +721,17 @@ public class TypeExtractor {
 							+ clazz.getCanonicalName() + "'.");
 				}
 			}
+			// check for Enum
+			else if (typeInfo instanceof EnumTypeInfo) {
+				if (!(type instanceof Class<?> && Enum.class.isAssignableFrom((Class<?>)
type))) {
+					throw new InvalidTypesException("Enum type expected.");
+				}
+				// check enum type contents
+				if (!(typeInfo.getTypeClass() == type)) {
+					throw new InvalidTypesException("Enum type '" + typeInfo.getTypeClass().getCanonicalName()
+ "' expected but was '"
+							+ typeToClass(type).getCanonicalName() + "'.");
+				}
+			}
 			// check for generic object
 			else if (typeInfo instanceof GenericTypeInfo<?>) {
 				Class<?> clazz = null;
@@ -867,7 +878,7 @@ public class TypeExtractor {
 	private <X> TypeInformation<X> privateGetForClass(Class<X> clazz, ArrayList<Type>
typeHierarchy) {
 		return privateGetForClass(clazz, typeHierarchy, null);
 	}
-	@SuppressWarnings("unchecked")
+	@SuppressWarnings({ "unchecked", "rawtypes" })
 	private <X> TypeInformation<X> privateGetForClass(Class<X> clazz, ArrayList<Type>
typeHierarchy, ParameterizedType clazzTypeHint) {
 		Validate.notNull(clazz);
 		
@@ -923,8 +934,9 @@ public class TypeExtractor {
 			throw new InvalidTypesException("Type information extraction for tuples cannot be done
based on the class.");
 		}
 
+		// check for Enums
 		if(Enum.class.isAssignableFrom(clazz)) {
-			return new EnumTypeInfo(clazz);
+			return (TypeInformation<X>) new EnumTypeInfo(clazz);
 		}
 
 		if (alreadySeen.contains(clazz)) {

http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/8724bf7c/flink-java/src/test/java/org/apache/flink/api/java/type/extractor/TypeExtractorTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/type/extractor/TypeExtractorTest.java
b/flink-java/src/test/java/org/apache/flink/api/java/type/extractor/TypeExtractorTest.java
index 00c0194..f8fb13c 100644
--- a/flink-java/src/test/java/org/apache/flink/api/java/type/extractor/TypeExtractorTest.java
+++ b/flink-java/src/test/java/org/apache/flink/api/java/type/extractor/TypeExtractorTest.java
@@ -44,6 +44,7 @@ import org.apache.flink.api.java.tuple.Tuple1;
 import org.apache.flink.api.java.tuple.Tuple2;
 import org.apache.flink.api.java.tuple.Tuple3;
 import org.apache.flink.api.java.tuple.Tuple9;
+import org.apache.flink.api.java.typeutils.EnumTypeInfo;
 import org.apache.flink.api.java.typeutils.ObjectArrayTypeInfo;
 import org.apache.flink.api.java.typeutils.PojoTypeInfo;
 import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
@@ -1602,4 +1603,25 @@ public class TypeExtractorTest {
 		Assert.assertTrue(ti.isBasicType());
 		Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti);
 	}
+	
+	public static enum MyEnum {
+		ONE, TWO, THREE
+	}
+	
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	@Test
+	public void testEnumType() {
+		MapFunction<?, ?> mf = new MapFunction<MyEnum, MyEnum>() {
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			public MyEnum map(MyEnum value) throws Exception {
+				return null;
+			}
+		};
+		
+		TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) mf, new EnumTypeInfo(MyEnum.class));
+		Assert.assertTrue(ti instanceof EnumTypeInfo);
+		Assert.assertEquals(ti.getTypeClass(), MyEnum.class);
+	}
 }


Mime
View raw message