Search in sources :

Example 1 with DataFormatConverter

use of org.apache.flink.table.data.util.DataFormatConverters.DataFormatConverter in project flink by apache.

the class DataFormatConvertersTest method test.

private static void test(TypeInformation typeInfo, Object value, Object anotherValue) {
    DataFormatConverter converter = getConverter(typeInfo);
    final Object innerValue = converter.toInternal(value);
    if (anotherValue != null) {
        converter.toInternal(anotherValue);
    }
    Assert.assertTrue(Arrays.deepEquals(new Object[] { converter.toExternal(innerValue) }, new Object[] { value }));
}
Also used : DataFormatConverter(org.apache.flink.table.data.util.DataFormatConverters.DataFormatConverter)

Example 2 with DataFormatConverter

use of org.apache.flink.table.data.util.DataFormatConverters.DataFormatConverter in project flink by apache.

the class DataFormatConvertersTest method testDataType.

private static void testDataType(DataType dataType, Object value) {
    DataFormatConverter converter = getConverter(dataType);
    Assert.assertTrue(Arrays.deepEquals(new Object[] { converter.toExternal(converter.toInternal(value)) }, new Object[] { value }));
}
Also used : DataFormatConverter(org.apache.flink.table.data.util.DataFormatConverters.DataFormatConverter)

Example 3 with DataFormatConverter

use of org.apache.flink.table.data.util.DataFormatConverters.DataFormatConverter in project flink by apache.

the class DataFormatConvertersTest method testTypes.

@Test
public void testTypes() {
    for (int i = 0; i < simpleTypes.length; i++) {
        test(simpleTypes[i], simpleValues[i]);
    }
    test(new RowTypeInfo(simpleTypes), new Row(simpleTypes.length));
    test(new RowTypeInfo(simpleTypes), Row.ofKind(RowKind.DELETE, simpleValues));
    test(InternalTypeInfo.ofFields(VarCharType.STRING_TYPE, new IntType()), GenericRowData.of(StringData.fromString("hehe"), 111));
    test(InternalTypeInfo.ofFields(VarCharType.STRING_TYPE, new IntType()), GenericRowData.of(null, null));
    test(new DecimalDataTypeInfo(10, 5), null);
    test(new DecimalDataTypeInfo(10, 5), DecimalDataUtils.castFrom(5.555, 10, 5));
    test(Types.BIG_DEC, null);
    {
        DataFormatConverter converter = getConverter(Types.BIG_DEC);
        Assert.assertTrue(Arrays.deepEquals(new Object[] { converter.toInternal(converter.toExternal(DecimalDataUtils.castFrom(5, 19, 18))) }, new Object[] { DecimalDataUtils.castFrom(5, 19, 18) }));
    }
    test(new ListTypeInfo<>(Types.STRING), null);
    test(new ListTypeInfo<>(Types.STRING), Arrays.asList("ahah", "xx"));
    test(BasicArrayTypeInfo.DOUBLE_ARRAY_TYPE_INFO, new Double[] { 1D, 5D });
    test(BasicArrayTypeInfo.DOUBLE_ARRAY_TYPE_INFO, new Double[] { null, null });
    test(ObjectArrayTypeInfo.getInfoFor(Types.STRING), new String[] { null, null });
    test(ObjectArrayTypeInfo.getInfoFor(Types.STRING), new String[] { "haha", "hehe" });
    test(ObjectArrayTypeInfo.getInfoFor(Types.STRING), new String[] { "haha", "hehe" }, new String[] { "aa", "bb" });
    test(new MapTypeInfo<>(Types.STRING, Types.INT), null);
    HashMap<String, Integer> map = new HashMap<>();
    map.put("haha", 1);
    map.put("hah1", 5);
    map.put(null, null);
    test(new MapTypeInfo<>(Types.STRING, Types.INT), map);
    Tuple2 tuple2 = new Tuple2<>(5, 10);
    TupleTypeInfo tupleTypeInfo = new TupleTypeInfo<>(tuple2.getClass(), Types.INT, Types.INT);
    test(tupleTypeInfo, tuple2);
    test(TypeExtractor.createTypeInfo(MyPojo.class), new MyPojo(1, 3));
}
Also used : HashMap(java.util.HashMap) DecimalDataTypeInfo(org.apache.flink.table.runtime.typeutils.DecimalDataTypeInfo) DataFormatConverter(org.apache.flink.table.data.util.DataFormatConverters.DataFormatConverter) RowTypeInfo(org.apache.flink.api.java.typeutils.RowTypeInfo) TupleTypeInfo(org.apache.flink.api.java.typeutils.TupleTypeInfo) IntType(org.apache.flink.table.types.logical.IntType) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Aggregations

DataFormatConverter (org.apache.flink.table.data.util.DataFormatConverters.DataFormatConverter)3 HashMap (java.util.HashMap)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 RowTypeInfo (org.apache.flink.api.java.typeutils.RowTypeInfo)1 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)1 DecimalDataTypeInfo (org.apache.flink.table.runtime.typeutils.DecimalDataTypeInfo)1 IntType (org.apache.flink.table.types.logical.IntType)1 Row (org.apache.flink.types.Row)1 Test (org.junit.Test)1