Search in sources :

Example 1 with NestedRowData

use of org.apache.flink.table.data.binary.NestedRowData in project flink by apache.

the class NestedRowDataTest method testNestInNestedRowData.

@Test
public void testNestInNestedRowData() {
    // layer1
    GenericRowData gRow = new GenericRowData(4);
    gRow.setField(0, 1);
    gRow.setField(1, 5L);
    gRow.setField(2, StringData.fromString("12345678"));
    gRow.setField(3, null);
    // layer2
    RowDataSerializer serializer = new RowDataSerializer(new LogicalType[] { DataTypes.INT().getLogicalType(), DataTypes.BIGINT().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.STRING().getLogicalType() }, new TypeSerializer[] { IntSerializer.INSTANCE, LongSerializer.INSTANCE, StringSerializer.INSTANCE, StringSerializer.INSTANCE });
    BinaryRowData row = new BinaryRowData(2);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeString(0, StringData.fromString("hahahahafff"));
    writer.writeRow(1, gRow, serializer);
    writer.complete();
    // layer3
    BinaryRowData row2 = new BinaryRowData(1);
    BinaryRowWriter writer2 = new BinaryRowWriter(row2);
    writer2.writeRow(0, row, null);
    writer2.complete();
    // verify
    {
        NestedRowData nestedRow = (NestedRowData) row2.getRow(0, 2);
        BinaryRowData binaryRow = new BinaryRowData(2);
        binaryRow.pointTo(nestedRow.getSegments(), nestedRow.getOffset(), nestedRow.getSizeInBytes());
        assertEquals(binaryRow, row);
    }
    assertEquals(row2.getRow(0, 2).getString(0), StringData.fromString("hahahahafff"));
    RowData nestedRow = row2.getRow(0, 2).getRow(1, 4);
    assertEquals(nestedRow.getInt(0), 1);
    assertEquals(nestedRow.getLong(1), 5L);
    assertEquals(nestedRow.getString(2), StringData.fromString("12345678"));
    assertTrue(nestedRow.isNullAt(3));
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) NestedRowData(org.apache.flink.table.data.binary.NestedRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) NestedRowData(org.apache.flink.table.data.binary.NestedRowData) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer) Test(org.junit.Test)

Aggregations

BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)1 NestedRowData (org.apache.flink.table.data.binary.NestedRowData)1 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)1 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)1 Test (org.junit.Test)1