Search in sources :

Example 36 with BinaryRowData

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

the class String2HashJoinOperatorTest method newRow.

public static BinaryRowData newRow(String... s) {
    BinaryRowData row = new BinaryRowData(s.length);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    for (int i = 0; i < s.length; i++) {
        if (s[i] == null) {
            writer.setNullAt(i);
        } else {
            writer.writeString(i, StringData.fromString(s[i]));
        }
    }
    writer.complete();
    return row;
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter)

Example 37 with BinaryRowData

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

the class RowDataTest method getBinaryRow.

private BinaryRowData getBinaryRow() {
    BinaryRowData row = new BinaryRowData(18);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeBoolean(0, true);
    writer.writeByte(1, (byte) 1);
    writer.writeShort(2, (short) 2);
    writer.writeInt(3, 3);
    writer.writeLong(4, 4);
    writer.writeFloat(5, 5);
    writer.writeDouble(6, 6);
    writer.writeString(8, str);
    writer.writeRawValue(9, generic, genericSerializer);
    writer.writeDecimal(10, decimal1, 5);
    writer.writeDecimal(11, decimal2, 20);
    writer.writeArray(12, array, new ArrayDataSerializer(DataTypes.INT().getLogicalType()));
    writer.writeMap(13, map, new MapDataSerializer(DataTypes.INT().getLogicalType(), DataTypes.INT().getLogicalType()));
    writer.writeRow(14, underRow, new RowDataSerializer(RowType.of(new IntType(), new IntType())));
    writer.writeBinary(15, bytes);
    writer.writeTimestamp(16, timestamp1, 3);
    writer.writeTimestamp(17, timestamp2, 9);
    return row;
}
Also used : MapDataSerializer(org.apache.flink.table.runtime.typeutils.MapDataSerializer) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) ArrayDataSerializer(org.apache.flink.table.runtime.typeutils.ArrayDataSerializer) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer) IntType(org.apache.flink.table.types.logical.IntType)

Example 38 with BinaryRowData

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

the class RowDataTest method testBinaryRow.

@Test
public void testBinaryRow() {
    BinaryRowData binaryRow = getBinaryRow();
    testGetters(binaryRow);
    testSetters(binaryRow);
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) Test(org.junit.Test)

Example 39 with BinaryRowData

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

the class RowDataTest method testNestedRow.

@Test
public void testNestedRow() {
    BinaryRowData row = new BinaryRowData(1);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeRow(0, getBinaryRow(), null);
    writer.complete();
    RowData nestedRow = row.getRow(0, 18);
    testGetters(nestedRow);
    testSetters(nestedRow);
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) Test(org.junit.Test)

Example 40 with BinaryRowData

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

the class RowDataTest method before.

@Before
public void before() {
    str = StringData.fromString("haha");
    generic = RawValueData.fromObject("haha");
    genericSerializer = new RawValueDataSerializer<>(StringSerializer.INSTANCE);
    decimal1 = DecimalData.fromUnscaledLong(10, 5, 0);
    decimal2 = DecimalData.fromBigDecimal(new BigDecimal(11), 20, 0);
    array = new BinaryArrayData();
    {
        BinaryArrayWriter arrayWriter = new BinaryArrayWriter(array, 2, 4);
        arrayWriter.writeInt(0, 15);
        arrayWriter.writeInt(1, 16);
        arrayWriter.complete();
    }
    map = BinaryMapData.valueOf(array, array);
    underRow = new BinaryRowData(2);
    {
        BinaryRowWriter writer = new BinaryRowWriter(underRow);
        writer.writeInt(0, 15);
        writer.writeInt(1, 16);
        writer.complete();
    }
    bytes = new byte[] { 1, 5, 6 };
    timestamp1 = TimestampData.fromEpochMillis(123L);
    timestamp2 = TimestampData.fromLocalDateTime(LocalDateTime.of(1969, 1, 1, 0, 0, 0, 123456789));
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Aggregations

BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)173 Test (org.junit.Test)81 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)54 RowData (org.apache.flink.table.data.RowData)31 ArrayList (java.util.ArrayList)30 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)22 UniformBinaryRowGenerator (org.apache.flink.table.runtime.util.UniformBinaryRowGenerator)21 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)16 MemorySegment (org.apache.flink.core.memory.MemorySegment)15 MutableObjectIterator (org.apache.flink.util.MutableObjectIterator)14 GenericRowData (org.apache.flink.table.data.GenericRowData)13 Random (java.util.Random)12 BinaryRowDataSerializer (org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)12 HashMap (java.util.HashMap)9 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)9 Map (java.util.Map)7 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)7 StreamOperator (org.apache.flink.streaming.api.operators.StreamOperator)7 RandomAccessInputView (org.apache.flink.runtime.io.disk.RandomAccessInputView)6 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)6