Search in sources :

Example 11 with BinaryArrayData

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

the class BinaryArrayDataTest method testDecimal.

@Test
public void testDecimal() {
    BinaryArrayData array = new BinaryArrayData();
    BinaryArrayWriter writer = new BinaryArrayWriter(array, 2, 8);
    // 1.compact
    {
        int precision = 4;
        int scale = 2;
        writer.reset();
        writer.writeDecimal(0, DecimalData.fromUnscaledLong(5, precision, scale), precision);
        writer.setNullAt(1);
        writer.complete();
        assertEquals("0.05", array.getDecimal(0, precision, scale).toString());
        assertTrue(array.isNullAt(1));
        array.setDecimal(0, DecimalData.fromUnscaledLong(6, precision, scale), precision);
        assertEquals("0.06", array.getDecimal(0, precision, scale).toString());
    }
    // 2.not compact
    {
        int precision = 25;
        int scale = 5;
        DecimalData decimal1 = DecimalData.fromBigDecimal(BigDecimal.valueOf(5.55), precision, scale);
        DecimalData decimal2 = DecimalData.fromBigDecimal(BigDecimal.valueOf(6.55), precision, scale);
        writer.reset();
        writer.writeDecimal(0, decimal1, precision);
        writer.writeDecimal(1, null, precision);
        writer.complete();
        assertEquals("5.55000", array.getDecimal(0, precision, scale).toString());
        assertTrue(array.isNullAt(1));
        array.setDecimal(0, decimal2, precision);
        assertEquals("6.55000", array.getDecimal(0, precision, scale).toString());
    }
}
Also used : BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData) Test(org.junit.Test)

Example 12 with BinaryArrayData

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

the class ArrayDataSerializer method deserialize.

@Override
public ArrayData deserialize(DataInputView source) throws IOException {
    BinaryArrayData array = new BinaryArrayData();
    deserializeInternal(source, array);
    return array;
}
Also used : BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData)

Example 13 with BinaryArrayData

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

the class MapDataSerializer method deserialize.

@Override
public MapData deserialize(DataInputView source) throws IOException {
    BinaryArrayData keyArray = new BinaryArrayData();
    BinaryArrayData valueArray = new BinaryArrayData();
    return deserializeInternal(source, keyArray, valueArray);
}
Also used : BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData)

Example 14 with BinaryArrayData

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

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

the class AbstractBinaryWriter method writeArray.

@Override
public void writeArray(int pos, ArrayData input, ArrayDataSerializer serializer) {
    BinaryArrayData binary = serializer.toBinaryArray(input);
    writeSegmentsToVarLenPart(pos, binary.getSegments(), binary.getOffset(), binary.getSizeInBytes());
}
Also used : BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData)

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