/** * Returns type information for Flink value types (classes that implement * {@link org.apache.flink.types.Value}). Built-in value types do not support null values (except * for {@link org.apache.flink.types.StringValue}). * * <p>Value types describe their serialization and deserialization manually. Instead of going * through a general purpose serialization framework. A value type is reasonable when general purpose * serialization would be highly inefficient. The wrapped value can be altered, allowing programmers to * reuse objects and take pressure off the garbage collector. * * <p>Flink provides built-in value types for all Java primitive types (such as * {@link org.apache.flink.types.BooleanValue}, {@link org.apache.flink.types.IntValue}) as well * as {@link org.apache.flink.types.StringValue}, {@link org.apache.flink.types.NullValue}, * {@link org.apache.flink.types.ListValue}, and {@link org.apache.flink.types.MapValue}. * * @param valueType class that implements {@link org.apache.flink.types.Value} */ public static <V extends Value> TypeInformation<V> VALUE(Class<V> valueType) { return new ValueTypeInfo<>(valueType); }
@Test public void testValueTypeEqualsWithNull() throws Exception { ValueTypeInfo<Record> tpeInfo = new ValueTypeInfo<>(Record.class); Assert.assertFalse(tpeInfo.equals(null)); }
@Override public boolean equals(Object obj) { if (obj instanceof ValueTypeInfo) { @SuppressWarnings("unchecked") ValueTypeInfo<T> valueTypeInfo = (ValueTypeInfo<T>) obj; return valueTypeInfo.canEqual(this) && type == valueTypeInfo.type; } else { return false; } }
@SuppressWarnings("unchecked") @PublicEvolving public static <X extends Tuple> TupleTypeInfo<X> getBasicAndBasicValueTupleTypeInfo(Class<?>... basicTypes) { if (basicTypes == null || basicTypes.length == 0) { throw new IllegalArgumentException(); } TypeInformation<?>[] infos = new TypeInformation<?>[basicTypes.length]; for (int i = 0; i < infos.length; i++) { Class<?> type = basicTypes[i]; if (type == null) { throw new IllegalArgumentException("Type at position " + i + " is null."); } TypeInformation<?> info = BasicTypeInfo.getInfoFor(type); if (info == null) { try { info = ValueTypeInfo.getValueTypeInfo((Class<Value>) type); if (!((ValueTypeInfo<?>) info).isBasicValueType()) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type."); } } catch (ClassCastException | InvalidTypesException e) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type.", e); } } infos[i] = info; } return (TupleTypeInfo<X>) new TupleTypeInfo<>(infos); }
@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()); }
if (!((ValueTypeInfo<?>) typeInfo).equals(actual = ValueTypeInfo.getValueTypeInfo((Class<? extends Value>) type))) { throw new InvalidTypesException("Value type '" + typeInfo + "' expected but was '" + actual + "'.");
return (TypeInformation<OUT>) ValueTypeInfo.getValueTypeInfo(valueClass);
return (TypeSerializer<T>) createCopyableValueSerializer(type.asSubclass(CopyableValue.class));
@Test public void testSubClassWithPartialsInHierarchie() throws Exception { CsvReader reader = getCsvReader(); DataSource<FinalItem> sitems = reader.tupleType(FinalItem.class); TypeInformation<?> info = sitems.getType(); Assert.assertEquals(true, info.isTupleType()); Assert.assertEquals(FinalItem.class, info.getTypeClass()); @SuppressWarnings("unchecked") TupleTypeInfo<SubItem> tinfo = (TupleTypeInfo<SubItem>) info; Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, tinfo.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tinfo.getTypeAt(1)); Assert.assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, tinfo.getTypeAt(2)); Assert.assertEquals(ValueTypeInfo.class, tinfo.getTypeAt(3).getClass()); Assert.assertEquals(ValueTypeInfo.class, tinfo.getTypeAt(4).getClass()); Assert.assertEquals(StringValue.class, ((ValueTypeInfo<?>) tinfo.getTypeAt(3)).getTypeClass()); Assert.assertEquals(LongValue.class, ((ValueTypeInfo<?>) tinfo.getTypeAt(4)).getTypeClass()); CsvInputFormat<?> inputFormat = (CsvInputFormat<?>) sitems.getInputFormat(); Assert.assertArrayEquals(new Class<?>[] {Integer.class, String.class, Double.class, StringValue.class, LongValue.class}, inputFormat.getFieldTypes()); }
if (!((ValueTypeInfo<?>) typeInfo).equals(actual = ValueTypeInfo.getValueTypeInfo((Class<? extends Value>) type))) { throw new InvalidTypesException("Value type '" + typeInfo + "' expected but was '" + actual + "'.");
@SuppressWarnings("unchecked") @PublicEvolving public static <X extends Tuple> TupleTypeInfo<X> getBasicAndBasicValueTupleTypeInfo(Class<?>... basicTypes) { if (basicTypes == null || basicTypes.length == 0) { throw new IllegalArgumentException(); } TypeInformation<?>[] infos = new TypeInformation<?>[basicTypes.length]; for (int i = 0; i < infos.length; i++) { Class<?> type = basicTypes[i]; if (type == null) { throw new IllegalArgumentException("Type at position " + i + " is null."); } TypeInformation<?> info = BasicTypeInfo.getInfoFor(type); if (info == null) { try { info = ValueTypeInfo.getValueTypeInfo((Class<Value>) type); if (!((ValueTypeInfo<?>) info).isBasicValueType()) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type."); } } catch (ClassCastException | InvalidTypesException e) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type.", e); } } infos[i] = info; } return (TupleTypeInfo<X>) new TupleTypeInfo<>(infos); }
clazz = loadClass(VALUE_PACKAGE + "." + className + "Value"); returnType = ValueTypeInfo.getValueTypeInfo((Class<Value>) clazz);
return (TypeSerializer<T>) createCopyableValueSerializer(type.asSubclass(CopyableValue.class));
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testFunctionDependingPartialOnInput() { RichMapFunction<?, ?> function = new OneAppender<DoubleValue>() { private static final long serialVersionUID = 1L; }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<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()); }
@Override protected ValueTypeInfo<?>[] getTestData() { return new ValueTypeInfo<?>[] { new ValueTypeInfo<>(TestClass.class), new ValueTypeInfo<>(AlternativeClass.class), new ValueTypeInfo<>(Record.class), }; }
if (!((ValueTypeInfo<?>) typeInfo).equals(actual = ValueTypeInfo.getValueTypeInfo((Class<? extends Value>) type))) { throw new InvalidTypesException("Value type '" + typeInfo + "' expected but was '" + actual + "'.");
@SuppressWarnings("unchecked") @PublicEvolving public static <X extends Tuple> TupleTypeInfo<X> getBasicAndBasicValueTupleTypeInfo(Class<?>... basicTypes) { if (basicTypes == null || basicTypes.length == 0) { throw new IllegalArgumentException(); } TypeInformation<?>[] infos = new TypeInformation<?>[basicTypes.length]; for (int i = 0; i < infos.length; i++) { Class<?> type = basicTypes[i]; if (type == null) { throw new IllegalArgumentException("Type at position " + i + " is null."); } TypeInformation<?> info = BasicTypeInfo.getInfoFor(type); if (info == null) { try { info = ValueTypeInfo.getValueTypeInfo((Class<Value>) type); if (!((ValueTypeInfo<?>) info).isBasicValueType()) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type."); } } catch (ClassCastException | InvalidTypesException e) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type.", e); } } infos[i] = info; } return (TupleTypeInfo<X>) new TupleTypeInfo<>(infos); }
return (TypeInformation<OUT>) ValueTypeInfo.getValueTypeInfo(valueClass);
@Override public boolean equals(Object obj) { if (obj instanceof ValueTypeInfo) { @SuppressWarnings("unchecked") ValueTypeInfo<T> valueTypeInfo = (ValueTypeInfo<T>) obj; return valueTypeInfo.canEqual(this) && type == valueTypeInfo.type; } else { return false; } }
return (TypeSerializer<T>) createCopyableValueSerializer(type.asSubclass(CopyableValue.class));