use of org.apache.flink.api.java.typeutils.runtime.RowSerializer in project flink by apache.
the class PythonTypeUtilsTest method testTypeInfoToSerializerConverter.
@Test
public void testTypeInfoToSerializerConverter() {
Map<TypeInformation, TypeSerializer> typeInformationTypeSerializerMap = new HashMap<>();
typeInformationTypeSerializerMap.put(BasicTypeInfo.INT_TYPE_INFO, IntSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.BIG_DEC_TYPE_INFO, BigDecSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.BIG_INT_TYPE_INFO, BigIntSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.CHAR_TYPE_INFO, CharSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.FLOAT_TYPE_INFO, FloatSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.DOUBLE_TYPE_INFO, DoubleSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.SHORT_TYPE_INFO, ShortSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.LONG_TYPE_INFO, LongSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.STRING_TYPE_INFO, StringSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.BYTE_TYPE_INFO, ByteSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(PickledByteArrayTypeInfo.PICKLED_BYTE_ARRAY_TYPE_INFO, BytePrimitiveArraySerializer.INSTANCE);
typeInformationTypeSerializerMap.put(BasicTypeInfo.BOOLEAN_TYPE_INFO, BooleanSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(SqlTimeTypeInfo.DATE, DateSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(SqlTimeTypeInfo.TIME, TimeSerializer.INSTANCE);
typeInformationTypeSerializerMap.put(SqlTimeTypeInfo.TIMESTAMP, new TimestampSerializer(3));
for (Map.Entry<TypeInformation, TypeSerializer> entry : typeInformationTypeSerializerMap.entrySet()) {
assertEquals(entry.getValue(), PythonTypeUtils.TypeInfoToSerializerConverter.typeInfoSerializerConverter(entry.getKey()));
}
TypeInformation primitiveIntegerArrayTypeInfo = PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO;
TypeSerializer convertedTypeSerializer = PythonTypeUtils.TypeInfoToSerializerConverter.typeInfoSerializerConverter(primitiveIntegerArrayTypeInfo);
assertEquals(convertedTypeSerializer, IntPrimitiveArraySerializer.INSTANCE);
TypeInformation integerArrayTypeInfo = BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO;
convertedTypeSerializer = PythonTypeUtils.TypeInfoToSerializerConverter.typeInfoSerializerConverter(integerArrayTypeInfo);
assertEquals(convertedTypeSerializer, new GenericArraySerializer(Integer.class, IntSerializer.INSTANCE));
TypeInformation objectArrayTypeInfo = Types.OBJECT_ARRAY(Types.ROW(Types.INT));
convertedTypeSerializer = PythonTypeUtils.TypeInfoToSerializerConverter.typeInfoSerializerConverter(objectArrayTypeInfo);
assertEquals(convertedTypeSerializer, new GenericArraySerializer(Row.class, new RowSerializer(new TypeSerializer[] { IntSerializer.INSTANCE }, null)));
TypeInformation rowTypeInfo = Types.ROW(Types.INT);
convertedTypeSerializer = PythonTypeUtils.TypeInfoToSerializerConverter.typeInfoSerializerConverter(rowTypeInfo);
assertEquals(convertedTypeSerializer, new RowSerializer(new TypeSerializer[] { IntSerializer.INSTANCE }, null));
TupleTypeInfo tupleTypeInfo = (TupleTypeInfo) Types.TUPLE(Types.INT);
convertedTypeSerializer = PythonTypeUtils.TypeInfoToSerializerConverter.typeInfoSerializerConverter(tupleTypeInfo);
assertEquals(convertedTypeSerializer, new TupleSerializer(tupleTypeInfo.getTypeClass(), new TypeSerializer[] { IntSerializer.INSTANCE }));
}
Aggregations