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());
}
}
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;
}
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);
}
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) };
}
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());
}
Aggregations