Search in sources :

Example 1 with BinaryRowWriter

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

the class BinaryMergeIteratorTest method newIterator.

private MutableObjectIterator<BinaryRowData> newIterator(final int[] keys, final String[] values) {
    BinaryRowData row = serializer.createInstance();
    BinaryRowWriter writer = new BinaryRowWriter(row);
    return new MutableObjectIterator<BinaryRowData>() {

        private int current = 0;

        @Override
        public BinaryRowData next(BinaryRowData reuse) {
            if (current < keys.length) {
                int key = keys[current];
                String value = values[current];
                current++;
                writer.reset();
                writer.writeInt(0, key);
                writer.writeString(1, StringData.fromString(value));
                writer.complete();
                return row;
            } else {
                return null;
            }
        }

        @Override
        public BinaryRowData next() {
            throw new RuntimeException();
        }
    };
}
Also used : MutableObjectIterator(org.apache.flink.util.MutableObjectIterator) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter)

Example 2 with BinaryRowWriter

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

the class RandomSortMergeInnerJoinTest method newRow.

public static BinaryRowData newRow(int i, String s1, String s2) {
    BinaryRowData row = new BinaryRowData(3);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeInt(0, i);
    if (s1 == null) {
        writer.setNullAt(1);
    } else {
        writer.writeString(1, StringData.fromString(s1));
    }
    if (s2 == null) {
        writer.setNullAt(2);
    } else {
        writer.writeString(2, StringData.fromString(s2));
    }
    writer.complete();
    return row;
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter)

Example 3 with BinaryRowWriter

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

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

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

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