Search in sources :

Example 16 with BinaryArrayWriter

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

the class BinaryArrayDataTest method testBinary.

@Test
public void testBinary() {
    BinaryArrayData array = new BinaryArrayData();
    BinaryArrayWriter writer = new BinaryArrayWriter(array, 2, 8);
    byte[] bytes1 = new byte[] { 1, -1, 5 };
    byte[] bytes2 = new byte[] { 1, -1, 5, 5, 1, 5, 1, 5 };
    writer.writeBinary(0, bytes1);
    writer.writeBinary(1, bytes2);
    writer.complete();
    Assert.assertArrayEquals(bytes1, array.getBinary(0));
    Assert.assertArrayEquals(bytes2, array.getBinary(1));
}
Also used : BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData) Test(org.junit.Test)

Example 17 with BinaryArrayWriter

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

the class ArrayObjectArrayConverter method open.

@Override
public void open(ClassLoader classLoader) {
    reuseArray = new BinaryArrayData();
    reuseWriter = new BinaryArrayWriter(reuseArray, 0, elementSize);
    elementConverter.open(classLoader);
}
Also used : BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData)

Example 18 with BinaryArrayWriter

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

the class ArrayDataSerializer method toBinaryArray.

public BinaryArrayData toBinaryArray(ArrayData from) {
    if (from instanceof BinaryArrayData) {
        return (BinaryArrayData) from;
    }
    int numElements = from.size();
    if (reuseArray == null) {
        reuseArray = new BinaryArrayData();
    }
    if (reuseWriter == null || reuseWriter.getNumElements() != numElements) {
        reuseWriter = new BinaryArrayWriter(reuseArray, numElements, BinaryArrayData.calculateFixLengthPartSize(eleType));
    } else {
        reuseWriter.reset();
    }
    for (int i = 0; i < numElements; i++) {
        if (from.isNullAt(i)) {
            reuseWriter.setNullAt(i, eleType);
        } else {
            BinaryWriter.write(reuseWriter, i, elementGetter.getElementOrNull(from, i), eleType, eleSer);
        }
    }
    reuseWriter.complete();
    return reuseArray;
}
Also used : BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData)

Example 19 with BinaryArrayWriter

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

the class MapDataSerializerTest method createArray.

private static BinaryArrayData createArray(int... vs) {
    BinaryArrayData array = new BinaryArrayData();
    BinaryArrayWriter writer = new BinaryArrayWriter(array, vs.length, 4);
    for (int i = 0; i < vs.length; i++) {
        writer.writeInt(i, vs[i]);
    }
    writer.complete();
    return array;
}
Also used : BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData)

Example 20 with BinaryArrayWriter

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

the class RowDataSerializerTest method createArray.

// ----------------------------------------------------------------------------------------------
private static BinaryArrayData createArray(int... ints) {
    BinaryArrayData array = new BinaryArrayData();
    BinaryArrayWriter writer = new BinaryArrayWriter(array, ints.length, 4);
    for (int i = 0; i < ints.length; i++) {
        writer.writeInt(i, ints[i]);
    }
    writer.complete();
    return array;
}
Also used : BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData)

Aggregations

BinaryArrayWriter (org.apache.flink.table.data.writer.BinaryArrayWriter)21 BinaryArrayData (org.apache.flink.table.data.binary.BinaryArrayData)19 Test (org.junit.Test)11 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)6 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)5 BinaryMapData (org.apache.flink.table.data.binary.BinaryMapData)4 ArrayDataSerializer (org.apache.flink.table.runtime.typeutils.ArrayDataSerializer)3 MapDataSerializer (org.apache.flink.table.runtime.typeutils.MapDataSerializer)3 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 MemorySegment (org.apache.flink.core.memory.MemorySegment)1 ArrayData (org.apache.flink.table.data.ArrayData)1 GenericMapData (org.apache.flink.table.data.GenericMapData)1 MapData (org.apache.flink.table.data.MapData)1 StringData.fromString (org.apache.flink.table.data.StringData.fromString)1 RawValueDataSerializer (org.apache.flink.table.runtime.typeutils.RawValueDataSerializer)1 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)1 IntType (org.apache.flink.table.types.logical.IntType)1 Before (org.junit.Before)1