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 }));
}
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 }));
}
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));
}
Aggregations