use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class FeatureUnitNormalizer method getSerializedData.
@Override
public byte[] getSerializedData() {
// Serialization format is (<key:int><min:double><max:double>)*
SliceOutput output = Slices.allocate((SizeOf.SIZE_OF_INT + 2 * SizeOf.SIZE_OF_DOUBLE) * mins.size()).getOutput();
for (int key : mins.keySet()) {
output.appendInt(key);
output.appendDouble(mins.get(key));
output.appendDouble(maxs.get(key));
}
return output.slice().getBytes();
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class VariableWidthBlockBuilder method copyPositions.
@Override
public Block copyPositions(List<Integer> positions) {
int finalLength = positions.stream().mapToInt(this::getSliceLength).sum();
SliceOutput newSlice = Slices.allocate(finalLength).getOutput();
int[] newOffsets = new int[positions.size() + 1];
boolean[] newValueIsNull = new boolean[positions.size()];
for (int i = 0; i < positions.size(); i++) {
int position = positions.get(i);
if (isEntryNull(position)) {
newValueIsNull[i] = true;
} else {
newSlice.appendBytes(sliceOutput.getUnderlyingSlice().getBytes(getPositionOffset(position), getSliceLength(position)));
}
newOffsets[i + 1] = newSlice.size();
}
return new VariableWidthBlock(positions.size(), newSlice.slice(), newOffsets, newValueIsNull);
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class FixedWidthBlock method copyPositions.
@Override
public Block copyPositions(List<Integer> positions) {
checkValidPositions(positions, positionCount);
SliceOutput newSlice = Slices.allocate(positions.size() * fixedSize).getOutput();
SliceOutput newValueIsNull = Slices.allocate(positions.size()).getOutput();
for (int position : positions) {
newSlice.writeBytes(slice, position * fixedSize, fixedSize);
newValueIsNull.writeByte(valueIsNull.getByte(position));
}
return new FixedWidthBlock(fixedSize, positions.size(), newSlice.slice(), newValueIsNull.slice());
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class FixedWidthBlockBuilder method copyPositions.
@Override
public Block copyPositions(List<Integer> positions) {
checkValidPositions(positions, positionCount);
SliceOutput newSlice = Slices.allocate(positions.size() * fixedSize).getOutput();
SliceOutput newValueIsNull = Slices.allocate(positions.size()).getOutput();
for (int position : positions) {
newValueIsNull.appendByte(valueIsNull.getUnderlyingSlice().getByte(position));
newSlice.appendBytes(getRawSlice().getBytes(position * fixedSize, fixedSize));
}
return new FixedWidthBlock(fixedSize, positions.size(), newSlice.slice(), newValueIsNull.slice());
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class AbstractTestHiveFileFormats method blockToSlice.
private static Slice blockToSlice(Block block) {
// This function is strictly for testing use only
SliceOutput sliceOutput = new DynamicSliceOutput(1000);
BlockSerdeUtil.writeBlock(sliceOutput, block.copyRegion(0, block.getPositionCount()));
return sliceOutput.slice();
}
Aggregations