Search in sources :

Example 16 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class BinaryRowDataTest method testRawValueData.

@Test
public void testRawValueData() {
    BinaryRowData row = new BinaryRowData(3);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    RawValueDataSerializer<String> binarySerializer = new RawValueDataSerializer<>(StringSerializer.INSTANCE);
    RawValueData<String> hahah = RawValueData.fromObject("hahah");
    writer.writeRawValue(0, hahah, binarySerializer);
    writer.setNullAt(1);
    writer.writeRawValue(2, hahah, binarySerializer);
    writer.complete();
    RawValueData<String> generic0 = row.getRawValue(0);
    assertThat(generic0, equivalent(hahah, binarySerializer));
    assertTrue(row.isNullAt(1));
    RawValueData<String> generic2 = row.getRawValue(2);
    assertThat(generic2, equivalent(hahah, binarySerializer));
}
Also used : RawValueDataSerializer(org.apache.flink.table.runtime.typeutils.RawValueDataSerializer) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) StringData.fromString(org.apache.flink.table.data.StringData.fromString) Test(org.junit.Test)

Example 17 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class NestedRowDataTest method getBinaryRowData.

private BinaryRowData getBinaryRowData() {
    BinaryRowData row = new BinaryRowData(1);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    GenericTypeInfo<MyObj> info = new GenericTypeInfo<>(MyObj.class);
    TypeSerializer<MyObj> genericSerializer = info.createSerializer(new ExecutionConfig());
    GenericRowData gRow = new GenericRowData(5);
    gRow.setField(0, 1);
    gRow.setField(1, 5L);
    gRow.setField(2, StringData.fromString("12345678"));
    gRow.setField(3, null);
    gRow.setField(4, RawValueData.fromObject(new MyObj(15, 5)));
    RowDataSerializer serializer = new RowDataSerializer(new LogicalType[] { DataTypes.INT().getLogicalType(), DataTypes.BIGINT().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.RAW(info.getTypeClass(), info.createSerializer(new ExecutionConfig())).getLogicalType() }, new TypeSerializer[] { IntSerializer.INSTANCE, LongSerializer.INSTANCE, StringDataSerializer.INSTANCE, StringDataSerializer.INSTANCE, new RawValueDataSerializer<>(genericSerializer) });
    writer.writeRow(0, gRow, serializer);
    writer.complete();
    return row;
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) MyObj(org.apache.flink.table.data.util.DataFormatTestUtil.MyObj) GenericTypeInfo(org.apache.flink.api.java.typeutils.GenericTypeInfo) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer)

Example 18 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter 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)

Example 19 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class DataFormatTestUtil method get160BytesBinaryRow.

/**
 * Get a binary row of 160 bytes long.
 */
public static BinaryRowData get160BytesBinaryRow() {
    // header (8 bytes) +
    // 72 byte length string (8 bytes in fixed-length, 72 bytes in variable-length) +
    // 64 byte length string (8 bytes in fixed-length, 64 bytes in variable-length)
    BinaryRowData row = new BinaryRowData(2);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeString(0, StringData.fromString(RandomStringUtils.randomNumeric(72)));
    writer.writeString(1, StringData.fromString(RandomStringUtils.randomNumeric(64)));
    writer.complete();
    return row;
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter)

Example 20 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class UniformBinaryRowGenerator method next.

@Override
public BinaryRowData next(BinaryRowData reuse) {
    if (!repeatKey) {
        if (valCnt >= numVals + startVal) {
            return null;
        }
        key.setValue(keyCnt++);
        value.setValue(valCnt);
        if (keyCnt == numKeys + startKey) {
            keyCnt = startKey;
            valCnt++;
        }
    } else {
        if (keyCnt >= numKeys + startKey) {
            return null;
        }
        key.setValue(keyCnt);
        value.setValue(valCnt++);
        if (valCnt == numVals + startVal) {
            valCnt = startVal;
            keyCnt++;
        }
    }
    BinaryRowWriter writer = new BinaryRowWriter(reuse);
    writer.writeInt(0, this.key.getValue());
    writer.writeInt(1, this.value.getValue());
    writer.complete();
    return reuse;
}
Also used : BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter)

Aggregations

BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)54 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)53 Test (org.junit.Test)32 Random (java.util.Random)6 BinaryArrayData (org.apache.flink.table.data.binary.BinaryArrayData)6 BinaryRowDataSerializer (org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)6 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)6 MemorySegment (org.apache.flink.core.memory.MemorySegment)5 BinaryArrayWriter (org.apache.flink.table.data.writer.BinaryArrayWriter)5 ArrayDataSerializer (org.apache.flink.table.runtime.typeutils.ArrayDataSerializer)5 ArrayList (java.util.ArrayList)4 GenericRowData (org.apache.flink.table.data.GenericRowData)4 MapDataSerializer (org.apache.flink.table.runtime.typeutils.MapDataSerializer)4 LogicalType (org.apache.flink.table.types.logical.LogicalType)4 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 StringData.fromString (org.apache.flink.table.data.StringData.fromString)3 TimestampData (org.apache.flink.table.data.TimestampData)3 RawValueDataSerializer (org.apache.flink.table.runtime.typeutils.RawValueDataSerializer)3 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2