TypeExtractor { @PublicEvolving public static <IN, OUT> TypeInformation<OUT> getMapReturnTypes(MapFunction<IN, OUT> mapInterface, TypeInformation<IN> inType) { return getMapReturnTypes(mapInterface, inType, null, false); } protected  TypeExtractor(); @PublicEvolving static TypeInformation<OUT> getMapReturnTypes(MapFunction<IN, OUT> mapInterface, TypeInformation<IN> inType); @PublicEvolving static TypeInformation<OUT> getMapReturnTypes(MapFunction<IN, OUT> mapInterface, TypeInformation<IN> inType,
			String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getFlatMapReturnTypes(FlatMapFunction<IN, OUT> flatMapInterface, TypeInformation<IN> inType); @PublicEvolving static TypeInformation<OUT> getFlatMapReturnTypes(FlatMapFunction<IN, OUT> flatMapInterface, TypeInformation<IN> inType,
			String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getFoldReturnTypes(FoldFunction<IN, OUT> foldInterface, TypeInformation<IN> inType); @PublicEvolving static TypeInformation<OUT> getFoldReturnTypes(FoldFunction<IN, OUT> foldInterface, TypeInformation<IN> inType, String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getMapPartitionReturnTypes(MapPartitionFunction<IN, OUT> mapPartitionInterface, TypeInformation<IN> inType); @PublicEvolving static TypeInformation<OUT> getMapPartitionReturnTypes(MapPartitionFunction<IN, OUT> mapPartitionInterface, TypeInformation<IN> inType,
			String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getGroupReduceReturnTypes(GroupReduceFunction<IN, OUT> groupReduceInterface, TypeInformation<IN> inType); @PublicEvolving static TypeInformation<OUT> getGroupReduceReturnTypes(GroupReduceFunction<IN, OUT> groupReduceInterface, TypeInformation<IN> inType,
			String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getGroupCombineReturnTypes(GroupCombineFunction<IN, OUT> combineInterface, TypeInformation<IN> inType); @PublicEvolving static TypeInformation<OUT> getGroupCombineReturnTypes(GroupCombineFunction<IN, OUT> combineInterface, TypeInformation<IN> inType,
																			String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getFlatJoinReturnTypes(FlatJoinFunction<IN1, IN2, OUT> joinInterface,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type); @PublicEvolving static TypeInformation<OUT> getFlatJoinReturnTypes(FlatJoinFunction<IN1, IN2, OUT> joinInterface,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getJoinReturnTypes(JoinFunction<IN1, IN2, OUT> joinInterface,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type); @PublicEvolving static TypeInformation<OUT> getJoinReturnTypes(JoinFunction<IN1, IN2, OUT> joinInterface,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getCoGroupReturnTypes(CoGroupFunction<IN1, IN2, OUT> coGroupInterface,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type); @PublicEvolving static TypeInformation<OUT> getCoGroupReturnTypes(CoGroupFunction<IN1, IN2, OUT> coGroupInterface,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getCrossReturnTypes(CrossFunction<IN1, IN2, OUT> crossInterface,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type); @PublicEvolving static TypeInformation<OUT> getCrossReturnTypes(CrossFunction<IN1, IN2, OUT> crossInterface,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type, String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<OUT> getKeySelectorTypes(KeySelector<IN, OUT> selectorInterface, TypeInformation<IN> inType); @PublicEvolving static TypeInformation<OUT> getKeySelectorTypes(KeySelector<IN, OUT> selectorInterface,
			TypeInformation<IN> inType, String functionName, boolean allowMissing); @PublicEvolving static TypeInformation<T> getPartitionerTypes(Partitioner<T> partitioner); @PublicEvolving static TypeInformation<T> getPartitionerTypes(Partitioner<T> partitioner, String functionName, boolean allowMissing); @SuppressWarnings("unchecked") @PublicEvolving static TypeInformation<IN> getInputFormatTypes(InputFormat<IN, ?> inputFormatInterface); @SuppressWarnings("unchecked") @PublicEvolving static TypeInformation<OUT> getUnaryOperatorReturnType(Function function, Class<?> baseClass, 
			boolean hasIterable, boolean hasCollector, TypeInformation<IN> inType,
			String functionName, boolean allowMissing); @SuppressWarnings("unchecked") @PublicEvolving static TypeInformation<OUT> getBinaryOperatorReturnType(Function function, Class<?> baseClass,
			boolean hasIterables, boolean hasCollector, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type,
			String functionName, boolean allowMissing); @SuppressWarnings("unchecked") static TypeInformation<T> createTypeInfo(Class<T> type); static TypeInformation<?> createTypeInfo(Type t); @SuppressWarnings("unchecked") @PublicEvolving static TypeInformation<OUT> createTypeInfo(Object instance, Class<?> baseClass, Class<?> clazz, int returnParamPos); @PublicEvolving static TypeInformation<OUT> createTypeInfo(Class<?> baseClass, Class<?> clazz, int returnParamPos,
			TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type); @PublicEvolving static Type getParameterType(Class<?> baseClass, Class<?> clazz, int pos); static TypeInformation<X> getForClass(Class<X> clazz); @PublicEvolving static List<Field> getAllDeclaredFields(Class<?> clazz); @PublicEvolving static Field getDeclaredField(Class<?> clazz, String name); @Internal static Class<?> typeToClass(Type t); @Internal static boolean isClassType(Type t); static TypeInformation<X> getForObject(X value);  }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testWritableType() { RichMapFunction<?, ?> function = new RichMapFunction<MyWritable, MyWritable>() { private static final long serialVersionUID = 1L; @Override public MyWritable map(MyWritable value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) new WritableTypeInfo<MyWritable>(MyWritable.class)); Assert.assertTrue(ti instanceof WritableTypeInfo<?>); Assert.assertEquals(MyWritable.class, ((WritableTypeInfo<?>) ti).getTypeClass()); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testGenericsNotInSuperclass() { RichMapFunction<?, ?> function = new RichMapFunction<LongKeyValue<String>, LongKeyValue<String>>() { private static final long serialVersionUID = 1L; @Override public LongKeyValue<String> map(LongKeyValue<String> value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2<Long, String>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(LongKeyValue.class, tti.getTypeClass()); Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testChainedGenericsNotInSuperclass() { RichMapFunction<?, ?> function = new RichMapFunction<ChainedTwo<Integer>, ChainedTwo<Integer>>() { private static final long serialVersionUID = 1L; @Override public ChainedTwo<Integer> map(ChainedTwo<Integer> value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3<String, Long, Integer>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(ChainedTwo.class, tti.getTypeClass()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, tti.getTypeAt(2)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testGenericsInDirectSuperclass() { RichMapFunction<?, ?> function = new RichMapFunction<ChainedThree, ChainedThree>() { private static final long serialVersionUID = 1L; @Override public ChainedThree map(ChainedThree value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3<String, Long, String>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(ChainedThree.class, tti.getTypeClass()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(2)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testGenericsNotInSuperclassWithNonGenericClassAtEnd() { RichMapFunction<?, ?> function = new RichMapFunction<ChainedFour, ChainedFour>() { private static final long serialVersionUID = 1L; @Override public ChainedFour map(ChainedFour value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3<String, Long, String>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(ChainedFour.class, tti.getTypeClass()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(2)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testMissingTupleGenerics() { RichMapFunction<?, ?> function = new RichMapFunction<String, Tuple2>() { private static final long serialVersionUID = 1L; @Override public Tuple2 map(String value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String"), "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String")); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testTupleSupertype() { RichMapFunction<?, ?> function = new RichMapFunction<String, Tuple>() { private static final long serialVersionUID = 1L; @Override public Tuple map(String value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String"), "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String")); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testSameGenericVariable() { RichMapFunction<?, ?> function = new RichMapFunction<SameTypeVariable<String>, SameTypeVariable<String>>() { private static final long serialVersionUID = 1L; @Override public SameTypeVariable<String> map(SameTypeVariable<String> value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2<String, String>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(SameTypeVariable.class, tti.getTypeClass()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testNestedTupleGenerics() { RichMapFunction<?, ?> function = new RichMapFunction<Nested<String, Integer>, Nested<String, Integer>>() { private static final long serialVersionUID = 1L; @Override public Nested<String, Integer> map(Nested<String, Integer> value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2<String, Tuple2<Integer, Integer>>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(Nested.class, tti.getTypeClass()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertTrue(tti.getTypeAt(1).isTupleType()); Assert.assertEquals(2, tti.getTypeAt(1).getArity()); TupleTypeInfo<?> tti2 = (TupleTypeInfo<?>) tti.getTypeAt(1); Assert.assertEquals(Tuple2.class, tti2.getTypeClass()); Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, tti2.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, tti2.getTypeAt(1)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testNestedTupleGenerics2() { RichMapFunction<?, ?> function = new RichMapFunction<Nested2<Boolean>, Nested2<Boolean>>() { private static final long serialVersionUID = 1L; @Override public Nested2<Boolean> map(Nested2<Boolean> value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2<Boolean, Tuple2<Tuple2<Integer, Tuple2<Boolean, Boolean>>, Tuple2<Integer, Tuple2<Boolean, Boolean>>>>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, tti.getTypeAt(0)); Assert.assertTrue(tti.getTypeAt(1).isTupleType()); TupleTypeInfo<?> tti2 = (TupleTypeInfo<?>) tti.getTypeAt(1); Assert.assertTrue(tti2.getTypeAt(0).isTupleType()); Assert.assertTrue(tti2.getTypeAt(1).isTupleType()); TupleTypeInfo<?> tti3 = (TupleTypeInfo<?>) tti2.getTypeAt(0); Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, tti3.getTypeAt(0)); Assert.assertTrue(tti3.getTypeAt(1).isTupleType()); TupleTypeInfo<?> tti4 = (TupleTypeInfo<?>) tti3.getTypeAt(1); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, tti4.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, tti4.getTypeAt(1)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testFunctionWithMissingGenerics() { RichMapFunction function = new RichMapFunction() { private static final long serialVersionUID = 1L; @Override public String map(Object value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, TypeInfoParser.parse("String"), "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { TypeExtractor.getMapReturnTypes(function, TypeInfoParser.parse("String")); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testFunctionDependingOnInputAsSuperclass() { IdentityMapper<Boolean> function = new IdentityMapper<Boolean>() { private static final long serialVersionUID = 1L; }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Boolean")); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, ti); }
@Test public void testFunctionDependingOnInputFromInput() { IdentityMapper<Boolean> function = new IdentityMapper<Boolean>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.BOOLEAN_TYPE_INFO); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, ti); }
@Test public void testFunctionDependingOnInputWithMissingInput() { IdentityMapper<Boolean> function = new IdentityMapper<Boolean>(); try { TypeExtractor.getMapReturnTypes(function, null); Assert.fail("exception expected"); } catch (InvalidTypesException e) { } }
@Test public void testFunctionDependingOnInputWithTupleInput() { IdentityMapper2<Boolean> function = new IdentityMapper2<Boolean>(); TypeInformation<Tuple2<Boolean, String>> inputType = new TupleTypeInfo<Tuple2<Boolean, String>>(BasicTypeInfo.BOOLEAN_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, inputType); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, ti); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testFunctionDependingOnInputWithCustomTupleInput() { IdentityMapper<SameTypeVariable<String>> function = new IdentityMapper<SameTypeVariable<String>>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2<String, String>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); }
@Test public void testFunctionDependingOnUnknownInput() { IdentityMapper3<Boolean, String> function = new IdentityMapper3<Boolean, String>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.BOOLEAN_TYPE_INFO, "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.BOOLEAN_TYPE_INFO); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { } }
@Test public void testFunctionDependingOnInputWithFunctionHierarchy() { IdentityMapper4<String> function = new IdentityMapper4<String>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.STRING_TYPE_INFO); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti); }
@Test public void testFunctionDependingOnInputWithFunctionHierarchy2() { IdentityMapper5<String> function = new IdentityMapper5<String>(); @SuppressWarnings({ "rawtypes", "unchecked" }) TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, new TupleTypeInfo(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO)); Assert.assertTrue(ti.isTupleType()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testFunctionWithNoGenericSuperclass() { RichMapFunction<?, ?> function = new Mapper2(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String")); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testFunctionDependingPartialOnInput() { RichMapFunction<?, ?> function = new OneAppender<DoubleValue>() { private static final long serialVersionUID = 1L; }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("DoubleValue")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertTrue(tti.getTypeAt(0) instanceof ValueTypeInfo<?>); ValueTypeInfo<?> vti = (ValueTypeInfo<?>) tti.getTypeAt(0); Assert.assertEquals(DoubleValue.class, vti.getTypeClass()); Assert.assertTrue(tti.getTypeAt(1).isBasicType()); Assert.assertEquals(Integer.class , tti.getTypeAt(1).getTypeClass()); }
@Test public void testFunctionDependingPartialOnInput2() { RichMapFunction<DoubleValue, ?> function = new OneAppender<DoubleValue>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, new ValueTypeInfo<DoubleValue>(DoubleValue.class)); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertTrue(tti.getTypeAt(0) instanceof ValueTypeInfo<?>); ValueTypeInfo<?> vti = (ValueTypeInfo<?>) tti.getTypeAt(0); Assert.assertEquals(DoubleValue.class, vti.getTypeClass()); Assert.assertTrue(tti.getTypeAt(1).isBasicType()); Assert.assertEquals(Integer.class , tti.getTypeAt(1).getTypeClass()); }
@Test public void testFunctionInputInOutputMultipleTimes() { RichMapFunction<Float, ?> function = new FieldDuplicator<Float>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.FLOAT_TYPE_INFO); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, tti.getTypeAt(1)); }
@Test public void testFunctionInputInOutputMultipleTimes2() { RichMapFunction<Tuple2<Float, Float>, ?> function = new FieldDuplicator<Tuple2<Float, Float>>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, new TupleTypeInfo<Tuple2<Float, Float>>( BasicTypeInfo.FLOAT_TYPE_INFO, BasicTypeInfo.FLOAT_TYPE_INFO)); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertTrue(tti.getTypeAt(0).isTupleType()); TupleTypeInfo<?> tti2 = (TupleTypeInfo<?>) tti.getTypeAt(0); Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, tti2.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, tti2.getTypeAt(1)); Assert.assertTrue(tti.getTypeAt(0).isTupleType()); TupleTypeInfo<?> tti3 = (TupleTypeInfo<?>) tti.getTypeAt(1); Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, tti3.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, tti3.getTypeAt(1)); }
@Test public void testAbstractAndInterfaceTypes() { RichMapFunction<String, ?> function = new RichMapFunction<String, Testable>() { private static final long serialVersionUID = 1L; @Override public Testable map(String value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.STRING_TYPE_INFO); Assert.assertTrue(ti instanceof GenericTypeInfo); RichMapFunction<String, ?> function2 = new RichMapFunction<String, AbstractClassWithoutMember>() { private static final long serialVersionUID = 1L; @Override public AbstractClassWithoutMember map(String value) throws Exception { return null; } }; ti = TypeExtractor.getMapReturnTypes(function2, BasicTypeInfo.STRING_TYPE_INFO); Assert.assertTrue(ti instanceof GenericTypeInfo); RichMapFunction<String, ?> function3 = new RichMapFunction<String, AbstractClassWithMember>() { private static final long serialVersionUID = 1L; @Override public AbstractClassWithMember map(String value) throws Exception { return null; } }; ti = TypeExtractor.getMapReturnTypes(function3, BasicTypeInfo.STRING_TYPE_INFO); Assert.assertTrue(ti instanceof PojoTypeInfo); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testValueSupertypeException() { RichMapFunction<?, ?> function = new RichMapFunction<StringValue, Value>() { private static final long serialVersionUID = 1L; @Override public Value map(StringValue value) throws Exception { return null; } }; TypeInformation<?> ti =TypeExtractor.getMapReturnTypes(function, (TypeInformation)TypeInfoParser.parse("StringValue"), "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { TypeExtractor.getMapReturnTypes(function, (TypeInformation)TypeInfoParser.parse("StringValue")); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { } }
@Test public void testBasicArray2() { RichMapFunction<Boolean[], ?> function = new IdentityMapper<Boolean[]>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicArrayTypeInfo.BOOLEAN_ARRAY_TYPE_INFO); Assert.assertTrue(ti instanceof BasicArrayTypeInfo<?, ?>); BasicArrayTypeInfo<?, ?> bati = (BasicArrayTypeInfo<?, ?>) ti; Assert.assertTrue(bati.getComponentInfo().isBasicType()); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, bati.getComponentInfo()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testCustomArray() { RichMapFunction<?, ?> function = new RichMapFunction<CustomArrayObject[], CustomArrayObject[]>() { private static final long serialVersionUID = 1L; @Override public CustomArrayObject[] map(CustomArrayObject[] value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("org.apache.flink.api.java.typeutils.TypeExtractorTest$CustomArrayObject[]")); Assert.assertTrue(ti instanceof ObjectArrayTypeInfo<?, ?>); Assert.assertEquals(CustomArrayObject.class, ((ObjectArrayTypeInfo<?, ?>) ti).getComponentInfo().getTypeClass()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testTupleArray() { RichMapFunction<?, ?> function = new RichMapFunction<Tuple2<String, String>[], Tuple2<String, String>[]>() { private static final long serialVersionUID = 1L; @Override public Tuple2<String, String>[] map(Tuple2<String, String>[] value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2<String, String>[]")); Assert.assertTrue(ti instanceof ObjectArrayTypeInfo<?, ?>); ObjectArrayTypeInfo<?, ?> oati = (ObjectArrayTypeInfo<?, ?>) ti; Assert.assertTrue(oati.getComponentInfo().isTupleType()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) oati.getComponentInfo(); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testCustomArrayWithTypeVariable() { RichMapFunction<CustomArrayObject2<Boolean>[], ?> function = new IdentityMapper<CustomArrayObject2<Boolean>[]>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple1<Boolean>[]")); Assert.assertTrue(ti instanceof ObjectArrayTypeInfo<?, ?>); ObjectArrayTypeInfo<?, ?> oati = (ObjectArrayTypeInfo<?, ?>) ti; Assert.assertTrue(oati.getComponentInfo().isTupleType()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) oati.getComponentInfo(); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, tti.getTypeAt(0)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testParameterizedArrays() { GenericArrayClass<Boolean> function = new GenericArrayClass<Boolean>(){ private static final long serialVersionUID = 1L; }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Boolean[]")); Assert.assertTrue(ti instanceof ObjectArrayTypeInfo<?,?>); ObjectArrayTypeInfo<?, ?> oati = (ObjectArrayTypeInfo<?, ?>) ti; Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, oati.getComponentInfo()); }
@Test public void testFunctionDependingOnInputWithTupleInputWithTypeMismatch() { IdentityMapper2<Boolean> function = new IdentityMapper2<Boolean>(); TypeInformation<Tuple2<Boolean, String>> inputType = new TupleTypeInfo<Tuple2<Boolean, String>>(BasicTypeInfo.BOOLEAN_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO); try { TypeExtractor.getMapReturnTypes(function, inputType); Assert.fail("exception expected"); } catch (InvalidTypesException e) { } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testInputMismatchExceptions() { RichMapFunction<?, ?> function = new RichMapFunction<Tuple2<String, String>, String>() { private static final long serialVersionUID = 1L; @Override public String map(Tuple2<String, String> value) throws Exception { return null; } }; try { TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2<Integer, String>")); Assert.fail("exception expected"); } catch (InvalidTypesException e) { } try { TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3<String, String, String>")); Assert.fail("exception expected"); } catch (InvalidTypesException e) { } RichMapFunction<?, ?> function2 = new RichMapFunction<StringValue, String>() { private static final long serialVersionUID = 1L; @Override public String map(StringValue value) throws Exception { return null; } }; try { TypeExtractor.getMapReturnTypes(function2, (TypeInformation) TypeInfoParser.parse("IntValue")); Assert.fail("exception expected"); } catch (InvalidTypesException e) { } RichMapFunction<?, ?> function3 = new RichMapFunction<Tuple1<Integer>[], String>() { private static final long serialVersionUID = 1L; @Override public String map(Tuple1<Integer>[] value) throws Exception { return null; } }; try { TypeExtractor.getMapReturnTypes(function3, (TypeInformation) TypeInfoParser.parse("Integer[]")); Assert.fail("exception expected"); } catch (InvalidTypesException e) { } RichMapFunction<?, ?> function4 = new RichMapFunction<Writable, String>() { private static final long serialVersionUID = 1L; @Override public String map(Writable value) throws Exception { return null; } }; try { TypeExtractor.getMapReturnTypes(function4, (TypeInformation) new WritableTypeInfo<MyWritable>(MyWritable.class)); Assert.fail("exception expected"); } catch (InvalidTypesException e) { } }
@Test public void testResultTypeQueryable() { TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(new MyQueryableMapper<Integer>(), BasicTypeInfo.STRING_TYPE_INFO); Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, ti); }
@Test public void testTupleWithPrimitiveArray() { RichMapFunction<Integer, Tuple9<int[],double[],long[],byte[],char[],float[],short[], boolean[], String[]>> function = new RichMapFunction<Integer, Tuple9<int[],double[],long[],byte[],char[],float[],short[], boolean[], String[]>>() { private static final long serialVersionUID = 1L; @Override public Tuple9<int[], double[], long[], byte[], char[], float[], short[], boolean[], String[]> map(Integer value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.INT_TYPE_INFO); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(PrimitiveArrayTypeInfo.DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(PrimitiveArrayTypeInfo.LONG_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(2)); Assert.assertEquals(PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(3)); Assert.assertEquals(PrimitiveArrayTypeInfo.CHAR_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(4)); Assert.assertEquals(PrimitiveArrayTypeInfo.FLOAT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(5)); Assert.assertEquals(PrimitiveArrayTypeInfo.SHORT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(6)); Assert.assertEquals(PrimitiveArrayTypeInfo.BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(7)); Assert.assertEquals(BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO, tti.getTypeAt(8)); }
@Test public void testFunction() { RichMapFunction<String, Boolean> mapInterface = new RichMapFunction<String, Boolean>() { private static final long serialVersionUID = 1L; @Override public void setRuntimeContext(RuntimeContext t) { } @Override public void open(Configuration parameters) throws Exception { } @Override public RuntimeContext getRuntimeContext() { return null; } @Override public void close() throws Exception { } @Override public Boolean map(String record) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(mapInterface, BasicTypeInfo.STRING_TYPE_INFO); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, ti); }
@Test public void testInterface() { MapFunction<String, Boolean> mapInterface = new MapFunction<String, Boolean>() { private static final long serialVersionUID = 1L; @Override public Boolean map(String record) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(mapInterface, BasicTypeInfo.STRING_TYPE_INFO); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, ti); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testDuplicateValue() { TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) new DuplicateValue<String>(), TypeInfoParser.parse("Tuple1<String>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testDuplicateValueNested() { TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) new DuplicateValueNested<String>(), TypeInfoParser.parse("Tuple1<Tuple1<String>>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testInputInference1() { EdgeMapper<String, Double> em = new EdgeMapper<String, Double>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInfoParser.parse("Tuple3<String, String, Double>")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, tti.getTypeAt(2)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testInputInference2() { EdgeMapper2<Boolean> em = new EdgeMapper2<Boolean>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInfoParser.parse("Boolean")); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, tti.getTypeAt(2)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testInputInference3() { EdgeMapper3<Boolean, String> em = new EdgeMapper3<Boolean, String>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInfoParser.parse("Tuple3<Boolean,Boolean,String>")); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testInputInference4() { EdgeMapper4<Boolean, String> em = new EdgeMapper4<Boolean, String>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInfoParser.parse("Tuple3<Boolean,Boolean,String>[]")); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti); }
@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); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testMultiDimensionalArray() { MapFunction<?,?> function = new MapFunction<Tuple2<Integer, Double>[][], Tuple2<Integer, Double>[][]>() { private static final long serialVersionUID = 1L; @Override public Tuple2<Integer, Double>[][] map( Tuple2<Integer, Double>[][] value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInfoParser.parse("Tuple2<Integer, Double>[][]")); Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<Java Tuple2<Integer, Double>>>", ti.toString()); function = new MapFunction<int[][][], int[][][]>() { private static final long serialVersionUID = 1L; @Override public int[][][] map( int[][][] value) throws Exception { return null; } }; ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInfoParser.parse("int[][][]")); Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<int[]>>", ti.toString()); function = new MapFunction<Integer[][][], Integer[][][]>() { private static final long serialVersionUID = 1L; @Override public Integer[][][] map( Integer[][][] value) throws Exception { return null; } }; ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInfoParser.parse("Integer[][][]")); Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<BasicArrayTypeInfo<Integer>>>", ti.toString()); function = new MapFunction<CustomType[][][], CustomType[][][]>() { private static final long serialVersionUID = 1L; @Override public CustomType[][][] map( CustomType[][][] value) throws Exception { return null; } }; ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInfoParser.parse("org.apache.flink.api.java.typeutils.TypeExtractorTest$CustomType<" + "myField1=String,myField2=int" + ">[][][]")); Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<" + "PojoType<org.apache.flink.api.java.typeutils.TypeExtractorTest$CustomType, fields = [myField1: String, myField2: Integer]>" + ">>>", ti.toString()); ti = TypeExtractor.getMapReturnTypes((MapFunction) new MapperWithMultiDimGenericArray<String>(), TypeInfoParser.parse("String[][][]")); Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<Java Tuple1<String>>>>", ti.toString()); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testInputMismatchWithRawFuntion() { MapFunction<?, ?> function = new MapWithResultTypeQueryable(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction)function, BasicTypeInfo.INT_TYPE_INFO); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti); }
@Test public void testEither() { MapFunction<?, ?> function = new MapFunction<Either<String, Boolean>, Either<String, Boolean>>() { @Override public Either<String, Boolean> map(Either<String, Boolean> value) throws Exception { return null; } }; TypeInformation<?> expected = new EitherTypeInfo(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.BOOLEAN_TYPE_INFO); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction) function, expected); Assert.assertEquals(expected, ti); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testInputWithCustomTypeInfo() { TypeInformation<?> customTypeInfo = new TypeInformation<Object>() { @Override public boolean isBasicType() { return true; } @Override public boolean isTupleType() { return true; } @Override public int getArity() { return 0; } @Override public int getTotalFields() { return 0; } @Override public Class getTypeClass() { return null; } @Override public boolean isKeyType() { return false; } @Override public TypeSerializer<Object> createSerializer(ExecutionConfig config) { return null; } @Override public String toString() { return null; } @Override public boolean equals(Object obj) { return false; } @Override public int hashCode() { return 0; } @Override public boolean canEqual(Object obj) { return false; } }; MapFunction<?, ?> function = new MapFunction<Tuple1<String>, Tuple1<Object>>() { @Override public Tuple1<Object> map(Tuple1<String> value) throws Exception { return null; } }; TypeExtractor.getMapReturnTypes(function, (TypeInformation) new TupleTypeInfo<Tuple1<Object>>(customTypeInfo)); }