Search in sources :

Example 16 with BinaryArrayData

use of org.apache.flink.table.data.binary.BinaryArrayData 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 17 with BinaryArrayData

use of org.apache.flink.table.data.binary.BinaryArrayData 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 18 with BinaryArrayData

use of org.apache.flink.table.data.binary.BinaryArrayData 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 19 with BinaryArrayData

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

Example 20 with BinaryArrayData

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

Aggregations

BinaryArrayData (org.apache.flink.table.data.binary.BinaryArrayData)27 BinaryArrayWriter (org.apache.flink.table.data.writer.BinaryArrayWriter)19 Test (org.junit.Test)11 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)7 BinaryMapData (org.apache.flink.table.data.binary.BinaryMapData)5 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)5 MemorySegment (org.apache.flink.core.memory.MemorySegment)3 ArrayDataSerializer (org.apache.flink.table.runtime.typeutils.ArrayDataSerializer)3 MapDataSerializer (org.apache.flink.table.runtime.typeutils.MapDataSerializer)3 BigDecimal (java.math.BigDecimal)2 IntType (org.apache.flink.table.types.logical.IntType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 QuickSort (org.apache.flink.runtime.operators.sort.QuickSort)1 ArrayData (org.apache.flink.table.data.ArrayData)1 GenericMapData (org.apache.flink.table.data.GenericMapData)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1 MapData (org.apache.flink.table.data.MapData)1 RawValueData (org.apache.flink.table.data.RawValueData)1 RowData (org.apache.flink.table.data.RowData)1