@PublicEvolving public static <IN1, IN2, OUT> TypeInformation<OUT> getCrossReturnTypes(CrossFunction<IN1, IN2, OUT> crossInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type) { return getCrossReturnTypes(crossInterface, in1Type, in2Type, null, false); }
/** * Finalizes a Cross transformation by applying a {@link CrossFunction} to each pair of crossed elements. * * <p>Each CrossFunction call returns exactly one element. * * @param function The CrossFunction that is called for each pair of crossed elements. * @return An CrossOperator that represents the crossed result DataSet * * @see CrossFunction * @see DataSet */ public <R> CrossOperator<I1, I2, R> with(CrossFunction<I1, I2, R> function) { if (function == null) { throw new NullPointerException("Cross function must not be null."); } TypeInformation<R> returnType = TypeExtractor.getCrossReturnTypes(function, getInput1().getType(), getInput2().getType(), super.getDefaultName(), true); return new CrossOperator<I1, I2, R>(getInput1(), getInput2(), clean(function), returnType, getCrossHint(), Utils.getCallLocationName()); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testPojo() { // use getCrossReturnTypes() RichCrossFunction<?, ?, ?> function = new RichCrossFunction<CustomType, Integer, CustomType>() { private static final long serialVersionUID = 1L; @Override public CustomType cross(CustomType first, Integer second) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getCrossReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<CustomType>(){}), (TypeInformation) Types.INT); Assert.assertFalse(ti.isBasicType()); Assert.assertFalse(ti.isTupleType()); Assert.assertTrue(ti instanceof PojoTypeInfo); Assert.assertEquals(ti.getTypeClass(), CustomType.class); // use getForClass() Assert.assertTrue(TypeExtractor.getForClass(CustomType.class) instanceof PojoTypeInfo); Assert.assertEquals(TypeExtractor.getForClass(CustomType.class).getTypeClass(), ti.getTypeClass()); // use getForObject() CustomType t = new CustomType("World", 1); TypeInformation<?> ti2 = TypeExtractor.getForObject(t); Assert.assertFalse(ti2.isBasicType()); Assert.assertFalse(ti2.isTupleType()); Assert.assertTrue(ti2 instanceof PojoTypeInfo); Assert.assertEquals(ti2.getTypeClass(), CustomType.class); Assert.assertFalse(TypeExtractor.getForClass(PojoWithNonPublicDefaultCtor.class) instanceof PojoTypeInfo); }
@PublicEvolving public static <IN1, IN2, OUT> TypeInformation<OUT> getCrossReturnTypes(CrossFunction<IN1, IN2, OUT> crossInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type) { return getCrossReturnTypes(crossInterface, in1Type, in2Type, null, false); }
@PublicEvolving public static <IN1, IN2, OUT> TypeInformation<OUT> getCrossReturnTypes(CrossFunction<IN1, IN2, OUT> crossInterface, TypeInformation<IN1> in1Type, TypeInformation<IN2> in2Type) { return getCrossReturnTypes(crossInterface, in1Type, in2Type, null, false); }
/** * Finalizes a Cross transformation by applying a {@link CrossFunction} to each pair of crossed elements. * * <p>Each CrossFunction call returns exactly one element. * * @param function The CrossFunction that is called for each pair of crossed elements. * @return An CrossOperator that represents the crossed result DataSet * * @see CrossFunction * @see DataSet */ public <R> CrossOperator<I1, I2, R> with(CrossFunction<I1, I2, R> function) { if (function == null) { throw new NullPointerException("Cross function must not be null."); } TypeInformation<R> returnType = TypeExtractor.getCrossReturnTypes(function, getInput1().getType(), getInput2().getType(), super.getDefaultName(), true); return new CrossOperator<I1, I2, R>(getInput1(), getInput2(), clean(function), returnType, getCrossHint(), Utils.getCallLocationName()); }
/** * Finalizes a Cross transformation by applying a {@link CrossFunction} to each pair of crossed elements. * * <p>Each CrossFunction call returns exactly one element. * * @param function The CrossFunction that is called for each pair of crossed elements. * @return An CrossOperator that represents the crossed result DataSet * * @see CrossFunction * @see DataSet */ public <R> CrossOperator<I1, I2, R> with(CrossFunction<I1, I2, R> function) { if (function == null) { throw new NullPointerException("Cross function must not be null."); } TypeInformation<R> returnType = TypeExtractor.getCrossReturnTypes(function, getInput1().getType(), getInput2().getType(), super.getDefaultName(), true); return new CrossOperator<I1, I2, R>(getInput1(), getInput2(), clean(function), returnType, getCrossHint(), Utils.getCallLocationName()); }