Search in sources :

Example 11 with BinaryArrayWriter

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

the class MapDataSerializerTest method getTestData.

@Override
protected MapData[] getTestData() {
    Map<Object, Object> first = new HashMap<>();
    first.put(1L, -100.1F);
    BinaryArrayData keyBinary = BinaryArrayData.fromPrimitiveArray(new long[] { 10L, 20L });
    BinaryArrayData valueBinary = new BinaryArrayData();
    BinaryArrayWriter writer = new BinaryArrayWriter(valueBinary, 2, 4);
    BinaryArrayWriter.NullSetter nullSetter = BinaryArrayWriter.createNullSetter(FLOAT);
    writer.writeFloat(0, 10.2F);
    nullSetter.setNull(writer, 1);
    writer.complete();
    return new MapData[] { new GenericMapData(first), BinaryMapData.valueOf(keyBinary, valueBinary) };
}
Also used : GenericMapData(org.apache.flink.table.data.GenericMapData) HashMap(java.util.HashMap) MapData(org.apache.flink.table.data.MapData) BinaryMapData(org.apache.flink.table.data.binary.BinaryMapData) GenericMapData(org.apache.flink.table.data.GenericMapData) BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData)

Example 12 with BinaryArrayWriter

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

the class BinaryRowDataTest method testBinaryArray.

@Test
public void testBinaryArray() {
    // 1. array test
    BinaryArrayData array = new BinaryArrayData();
    BinaryArrayWriter arrayWriter = new BinaryArrayWriter(array, 3, BinaryArrayData.calculateFixLengthPartSize(DataTypes.INT().getLogicalType()));
    arrayWriter.writeInt(0, 6);
    arrayWriter.setNullInt(1);
    arrayWriter.writeInt(2, 666);
    arrayWriter.complete();
    assertEquals(array.getInt(0), 6);
    assertTrue(array.isNullAt(1));
    assertEquals(array.getInt(2), 666);
    // 2. test write array to binary row
    BinaryRowData row = new BinaryRowData(1);
    BinaryRowWriter rowWriter = new BinaryRowWriter(row);
    ArrayDataSerializer serializer = new ArrayDataSerializer(DataTypes.INT().getLogicalType());
    rowWriter.writeArray(0, array, serializer);
    rowWriter.complete();
    BinaryArrayData array2 = (BinaryArrayData) row.getArray(0);
    assertEquals(array, array2);
    assertEquals(6, array2.getInt(0));
    assertTrue(array2.isNullAt(1));
    assertEquals(666, array2.getInt(2));
}
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) ArrayDataSerializer(org.apache.flink.table.runtime.typeutils.ArrayDataSerializer) Test(org.junit.Test)

Example 13 with BinaryArrayWriter

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

the class BinaryRowDataTest method testBinaryMap.

@Test
public void testBinaryMap() {
    BinaryArrayData array1 = new BinaryArrayData();
    BinaryArrayWriter writer1 = new BinaryArrayWriter(array1, 4, BinaryArrayData.calculateFixLengthPartSize(DataTypes.INT().getLogicalType()));
    writer1.writeInt(0, 6);
    writer1.writeInt(1, 5);
    writer1.writeInt(2, 666);
    writer1.writeInt(3, 0);
    writer1.complete();
    BinaryArrayData array2 = new BinaryArrayData();
    BinaryArrayWriter writer2 = new BinaryArrayWriter(array2, 4, BinaryArrayData.calculateFixLengthPartSize(DataTypes.STRING().getLogicalType()));
    writer2.writeString(0, fromString("6"));
    writer2.writeString(1, fromString("5"));
    writer2.writeString(2, fromString("666"));
    writer2.setNullAt(3, DataTypes.STRING().getLogicalType());
    writer2.complete();
    BinaryMapData binaryMap = BinaryMapData.valueOf(array1, array2);
    BinaryRowData row = new BinaryRowData(1);
    BinaryRowWriter rowWriter = new BinaryRowWriter(row);
    MapDataSerializer serializer = new MapDataSerializer(DataTypes.STRING().getLogicalType(), DataTypes.INT().getLogicalType());
    rowWriter.writeMap(0, binaryMap, serializer);
    rowWriter.complete();
    BinaryMapData map = (BinaryMapData) row.getMap(0);
    BinaryArrayData key = map.keyArray();
    BinaryArrayData value = map.valueArray();
    assertEquals(binaryMap, map);
    assertEquals(array1, key);
    assertEquals(array2, value);
    assertEquals(5, key.getInt(1));
    assertEquals(fromString("5"), value.getString(1));
    assertEquals(0, key.getInt(3));
    assertTrue(value.isNullAt(3));
}
Also used : BinaryMapData(org.apache.flink.table.data.binary.BinaryMapData) MapDataSerializer(org.apache.flink.table.runtime.typeutils.MapDataSerializer) 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) Test(org.junit.Test)

Example 14 with BinaryArrayWriter

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

the class BinaryArrayDataTest method testGeneric.

@Test
public void testGeneric() {
    BinaryArrayData array = new BinaryArrayData();
    BinaryArrayWriter writer = new BinaryArrayWriter(array, 2, 8);
    RawValueData<String> generic = RawValueData.fromObject("hahah");
    RawValueDataSerializer<String> serializer = new RawValueDataSerializer<>(StringSerializer.INSTANCE);
    writer.writeRawValue(0, generic, serializer);
    writer.setNullAt(1);
    writer.complete();
    RawValueData<String> newGeneric = array.getRawValue(0);
    assertThat(newGeneric, equivalent(generic, serializer));
    assertTrue(array.isNullAt(1));
}
Also used : RawValueDataSerializer(org.apache.flink.table.runtime.typeutils.RawValueDataSerializer) BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) StringData.fromString(org.apache.flink.table.data.StringData.fromString) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData) Test(org.junit.Test)

Example 15 with BinaryArrayWriter

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

the class BinaryArrayDataTest method testMap.

@Test
public void testMap() {
    BinaryArrayData array1 = new BinaryArrayData();
    BinaryArrayWriter writer1 = new BinaryArrayWriter(array1, 3, 4);
    writer1.writeInt(0, 6);
    writer1.writeInt(1, 5);
    writer1.writeInt(2, 666);
    writer1.complete();
    BinaryArrayData array2 = new BinaryArrayData();
    BinaryArrayWriter writer2 = new BinaryArrayWriter(array2, 3, 8);
    writer2.writeString(0, fromString("6"));
    writer2.writeString(1, fromString("5"));
    writer2.writeString(2, fromString("666"));
    writer2.complete();
    BinaryMapData binaryMap = BinaryMapData.valueOf(array1, array2);
    BinaryRowData row = new BinaryRowData(1);
    BinaryRowWriter rowWriter = new BinaryRowWriter(row);
    rowWriter.writeMap(0, binaryMap, new MapDataSerializer(DataTypes.INT().getLogicalType(), DataTypes.INT().getLogicalType()));
    rowWriter.complete();
    BinaryMapData map = (BinaryMapData) row.getMap(0);
    BinaryArrayData key = map.keyArray();
    BinaryArrayData value = map.valueArray();
    assertEquals(binaryMap, map);
    assertEquals(array1, key);
    assertEquals(array2, value);
    assertEquals(key.getInt(1), 5);
    assertEquals(value.getString(1), fromString("5"));
}
Also used : BinaryMapData(org.apache.flink.table.data.binary.BinaryMapData) MapDataSerializer(org.apache.flink.table.runtime.typeutils.MapDataSerializer) 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) Test(org.junit.Test)

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