/** * Gets the type information of the component type. * @return The type information of the component type. */ @PublicEvolving public TypeInformation<?> getComponentType() { return BasicTypeInfo.getInfoFor(getComponentClass()); }
@Before public void setUp() throws Exception { if (!mapStateDesc.isSerializerInitialized()) { mapStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); } Map<Long, Long> initMap = new HashMap<>(); initMap.put(1L, 5L); initMap.put(2L, 5L); byte[] initSer = KvStateSerializer.serializeMap( initMap.entrySet(), BasicTypeInfo.LONG_TYPE_INFO.createSerializer(new ExecutionConfig()), BasicTypeInfo.LONG_TYPE_INFO.createSerializer(new ExecutionConfig())); mapState = ImmutableMapState.createState(mapStateDesc, initSer); }
@Override public boolean equals(Object obj) { if (obj instanceof BasicTypeInfo) { @SuppressWarnings("unchecked") BasicTypeInfo<T> other = (BasicTypeInfo<T>) obj; return other.canEqual(this) && this.clazz == other.clazz && serializer.equals(other.serializer) && this.comparatorClass == other.comparatorClass; } else { return false; } }
@Test public void testBasicTypeInfoEquality() { for (Class<?> clazz: classes) { BasicTypeInfo<?> tpeInfo1 = BasicTypeInfo.getInfoFor(clazz); BasicTypeInfo<?> tpeInfo2 = BasicTypeInfo.getInfoFor(clazz); assertEquals(tpeInfo1, tpeInfo2); assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); } }
@Override @PublicEvolving public TypeComparator<T> createComparator(boolean sortOrderAscending, ExecutionConfig executionConfig) { if (comparatorClass != null) { return instantiateComparator(comparatorClass, sortOrderAscending); } else { throw new InvalidTypesException("The type " + clazz.getSimpleName() + " cannot be used as a key."); } }
/** * Returns whether this type should be automatically casted to * the target type in an arithmetic operation. */ @PublicEvolving public boolean shouldAutocastTo(BasicTypeInfo<?> to) { for (Class<?> possibleTo: possibleCastTargetTypes) { if (possibleTo.equals(to.getTypeClass())) { return true; } } return false; }
@Override public boolean shouldAutocastTo(BasicTypeInfo<?> to) { return (to.getTypeClass() == BigDecimal.class) || super.shouldAutocastTo(to); }
@Override @PublicEvolving public TypeComparator<T> createComparator(boolean sortOrderAscending, ExecutionConfig executionConfig) { if (comparatorClass != null) { return instantiateComparator(comparatorClass, sortOrderAscending); } else { throw new InvalidTypesException("The type " + clazz.getSimpleName() + " cannot be used as a key."); } }
/** * Returns whether this type should be automatically casted to * the target type in an arithmetic operation. */ @PublicEvolving public boolean shouldAutocastTo(BasicTypeInfo<?> to) { for (Class<?> possibleTo: possibleCastTargetTypes) { if (possibleTo.equals(to.getTypeClass())) { return true; } } return false; }
public ArrayFieldAccessor(int pos, TypeInformation typeInfo) { if (pos < 0) { throw new CompositeType.InvalidFieldReferenceException("The " + ((Integer) pos).toString() + ". field selected on" + " an array, which is an invalid index."); } checkNotNull(typeInfo, "typeInfo must not be null."); this.pos = pos; this.fieldType = BasicTypeInfo.getInfoFor(typeInfo.getTypeClass().getComponentType()); }
@Test public void testStrings() { try { String[] data = { "Oh", "boy", "what", "a", "show", "!"}; FromElementsFunction<String> source = new FromElementsFunction<String>( BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), data); List<String> result = new ArrayList<String>(); source.run(new ListSourceContext<String>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Override @PublicEvolving public TypeComparator<T> createComparator(boolean sortOrderAscending, ExecutionConfig executionConfig) { if (comparatorClass != null) { return instantiateComparator(comparatorClass, sortOrderAscending); } else { throw new InvalidTypesException("The type " + clazz.getSimpleName() + " cannot be used as a key."); } }
/** * Returns whether this type should be automatically casted to * the target type in an arithmetic operation. */ @PublicEvolving public boolean shouldAutocastTo(BasicTypeInfo<?> to) { for (Class<?> possibleTo: possibleCastTargetTypes) { if (possibleTo.equals(to.getTypeClass())) { return true; } } return false; }
@Override public boolean equals(Object obj) { if (obj instanceof BasicTypeInfo) { @SuppressWarnings("unchecked") BasicTypeInfo<T> other = (BasicTypeInfo<T>) obj; return other.canEqual(this) && this.clazz == other.clazz && serializer.equals(other.serializer) && this.comparatorClass == other.comparatorClass; } else { return false; } }
@PublicEvolving public static <X extends Tuple> TupleTypeInfo<X> getBasicTupleTypeInfo(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) { throw new IllegalArgumentException("Type at position " + i + " is not a basic type."); } infos[i] = info; } @SuppressWarnings("unchecked") TupleTypeInfo<X> tupleInfo = (TupleTypeInfo<X>) new TupleTypeInfo<Tuple>(infos); return tupleInfo; }
CollectionInputFormat<String> inputFormat = new CollectionInputFormat<String>(inputCollection, BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()));
@Override public boolean equals(Object obj) { if (obj instanceof BasicTypeInfo) { @SuppressWarnings("unchecked") BasicTypeInfo<T> other = (BasicTypeInfo<T>) obj; return other.canEqual(this) && this.clazz == other.clazz && serializer.equals(other.serializer) && this.comparatorClass == other.comparatorClass; } else { return false; } }
@Test public void testBasicTypeInfoInequality() { for (Class<?> clazz1: classes) { for (Class<?> clazz2: classes) { if (!clazz1.equals(clazz2)) { BasicTypeInfo<?> tpeInfo1 = BasicTypeInfo.getInfoFor(clazz1); BasicTypeInfo<?> tpeInfo2 = BasicTypeInfo.getInfoFor(clazz2); assertNotEquals(tpeInfo1, tpeInfo2); } } } } }
.chain(chainedOperatorId, chainedOperator, BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())) .finish();
@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); }