Search in sources :

Example 1 with RowSerializer

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 }));
}
Also used : HashMap(java.util.HashMap) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) TupleTypeInfo(org.apache.flink.api.java.typeutils.TupleTypeInfo) GenericArraySerializer(org.apache.flink.api.common.typeutils.base.GenericArraySerializer) TupleSerializer(org.apache.flink.api.java.typeutils.runtime.TupleSerializer) RowSerializer(org.apache.flink.api.java.typeutils.runtime.RowSerializer) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) TimestampSerializer(org.apache.flink.table.runtime.typeutils.serializers.python.TimestampSerializer) Row(org.apache.flink.types.Row) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)1 GenericArraySerializer (org.apache.flink.api.common.typeutils.base.GenericArraySerializer)1 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)1 RowSerializer (org.apache.flink.api.java.typeutils.runtime.RowSerializer)1 TupleSerializer (org.apache.flink.api.java.typeutils.runtime.TupleSerializer)1 TimestampSerializer (org.apache.flink.table.runtime.typeutils.serializers.python.TimestampSerializer)1 Row (org.apache.flink.types.Row)1 Test (org.junit.Test)1