use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class RowDataSerializerTest method testRowDataSerializerWithNestedRow.
private static Object[] testRowDataSerializerWithNestedRow() {
final DataType nestedDataType = DataTypes.ROW(DataTypes.FIELD("ri", DataTypes.INT()), DataTypes.FIELD("rs", DataTypes.STRING()), DataTypes.FIELD("rb", DataTypes.BIGINT()));
final DataType outerDataType = DataTypes.ROW(DataTypes.FIELD("i", DataTypes.INT()), DataTypes.FIELD("r", nestedDataType), DataTypes.FIELD("s", DataTypes.STRING()));
final TypeSerializer<RowData> nestedSerializer = InternalSerializers.create(nestedDataType.getLogicalType());
final RowDataSerializer outerSerializer = (RowDataSerializer) InternalSerializers.<RowData>create(outerDataType.getLogicalType());
final GenericRowData outerRow1 = GenericRowData.of(12, GenericRowData.of(34, StringData.fromString("56"), 78L), StringData.fromString("910"));
final RowData nestedRow1 = outerSerializer.toBinaryRow(outerRow1).getRow(1, 3);
final GenericRowData outerRow2 = GenericRowData.of(12, GenericRowData.of(null, StringData.fromString("56"), 78L), null);
final RowData nestedRow2 = outerSerializer.toBinaryRow(outerRow2).getRow(1, 3);
return new Object[] { nestedSerializer, new RowData[] { nestedRow1, nestedRow2 } };
}
use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class RowDataSerializerTest method testRowDataSerializerWithComplexTypes.
private static Object[] testRowDataSerializerWithComplexTypes() {
InternalTypeInfo<RowData> typeInfo = InternalTypeInfo.ofFields(new IntType(), new DoubleType(), VarCharType.STRING_TYPE, new ArrayType(new IntType()), new MapType(new IntType(), new IntType()));
GenericRowData[] data = new GenericRowData[] { createRow(null, null, null, null, null), createRow(0, null, null, null, null), createRow(0, 0.0, null, null, null), createRow(0, 0.0, fromString("a"), null, null), createRow(1, 0.0, fromString("a"), null, null), createRow(1, 1.0, fromString("a"), null, null), createRow(1, 1.0, fromString("b"), null, null), createRow(1, 1.0, fromString("b"), createArray(1), createMap(new int[] { 1 }, new int[] { 1 })), createRow(1, 1.0, fromString("b"), createArray(1, 2), createMap(new int[] { 1, 4 }, new int[] { 1, 2 })), createRow(1, 1.0, fromString("b"), createArray(1, 2, 3), createMap(new int[] { 1, 5 }, new int[] { 1, 3 })), createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4), createMap(new int[] { 1, 6 }, new int[] { 1, 4 })), createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4, 5), createMap(new int[] { 1, 7 }, new int[] { 1, 5 })), createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4, 5, 6), createMap(new int[] { 1, 8 }, new int[] { 1, 6 })) };
RowDataSerializer serializer = typeInfo.toRowSerializer();
return new Object[] { serializer, data };
}
use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class RowDataSerializerTest method createRow.
private static GenericRowData createRow(Object f0, Object f1, Object f2, Object f3, Object f4) {
GenericRowData row = new GenericRowData(5);
row.setField(0, f0);
row.setField(1, f1);
row.setField(2, f2);
row.setField(3, f3);
row.setField(4, f4);
return row;
}
use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class RowDataTestUtil method toGenericRowDeeply.
public static GenericRowData toGenericRowDeeply(RowData rowData, List<LogicalType> types) {
if (rowData instanceof GenericRowData) {
return (GenericRowData) rowData;
} else {
int fieldNum = rowData.getArity();
GenericRowData row = new GenericRowData(fieldNum);
row.setRowKind(rowData.getRowKind());
for (int i = 0; i < fieldNum; i++) {
if (rowData.isNullAt(i)) {
row.setField(i, null);
} else {
LogicalType type = types.get(i);
RowData.FieldGetter fieldGetter = RowData.createFieldGetter(type, i);
Object o = fieldGetter.getFieldOrNull(rowData);
if (type instanceof RowType) {
o = toGenericRowDeeply((RowData) o, type.getChildren());
}
row.setField(i, o);
}
}
return row;
}
}
use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class TableAssertionTest method testAssertRowDataWithConversion.
@Test
void testAssertRowDataWithConversion() {
DataType dataType = ROW(FIELD("a", INT()), FIELD("b", STRING()), FIELD("c", ARRAY(BOOLEAN().notNull())));
GenericRowData genericRowData = GenericRowData.of(10, StringData.fromString("my string"), new GenericArrayData(new boolean[] { true, false }));
BinaryRowData binaryRowData = new RowDataSerializer((RowType) dataType.getLogicalType()).toBinaryRow(genericRowData);
Row row = Row.of(10, "my string", new Boolean[] { true, false });
// Test equality with RowData
assertThat(binaryRowData).asGeneric(dataType).isEqualTo(genericRowData).isEqualTo(binaryRowData.copy());
assertThatRows(binaryRowData).asGeneric(dataType).containsOnly(genericRowData).containsOnly(binaryRowData);
// Test equality with Row
assertThat(binaryRowData).asRow(dataType).isEqualTo(row);
assertThatRows(binaryRowData).asRows(dataType).containsOnly(row);
}
Aggregations