use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class TestRcFileDecoderUtils method testVInt.
@Test
public void testVInt() throws Exception {
Slice slice = Slices.allocate(100);
SliceOutput output = slice.getOutput();
assertVIntRoundTrip(output, 0);
assertVIntRoundTrip(output, 1);
assertVIntRoundTrip(output, -1);
assertVIntRoundTrip(output, Integer.MAX_VALUE);
assertVIntRoundTrip(output, Integer.MAX_VALUE + 1L);
assertVIntRoundTrip(output, Integer.MAX_VALUE - 1L);
assertVIntRoundTrip(output, Integer.MIN_VALUE);
assertVIntRoundTrip(output, Integer.MIN_VALUE + 1L);
assertVIntRoundTrip(output, Integer.MIN_VALUE - 1L);
assertVIntRoundTrip(output, Long.MAX_VALUE);
assertVIntRoundTrip(output, Long.MAX_VALUE - 1);
assertVIntRoundTrip(output, Long.MIN_VALUE + 1);
for (int value = -100_000; value < 100_000; value++) {
assertVIntRoundTrip(output, value);
}
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class TestRcFileReaderManual method testStartSync.
@Test
public void testStartSync() throws Exception {
SliceOutput output = new DynamicSliceOutput(10 * 1024);
List<Segment> segments = ImmutableList.of(writeSegment(output, ImmutableList.of()), writeSegment(output, ImmutableList.of(ImmutableList.of(0, 2, 3, 4), ImmutableList.of(10, 12, 13))), writeSegment(output, ImmutableList.of(ImmutableList.of(20, 22), ImmutableList.of(30, 33), ImmutableList.of(40, 44))), writeSegment(output, ImmutableList.of(ImmutableList.of(100, 101, 102))));
assertFileSegments(output.slice(), segments);
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class StringEncoding method unescape.
@SuppressWarnings("AssignmentToForLoopParameter")
private static ColumnData unescape(ColumnData columnData, byte escapeByte) {
Slice slice = columnData.getSlice();
// does slice contain escape byte
if (slice.indexOfByte(escapeByte) < 0) {
return columnData;
}
Slice newSlice = Slices.allocate(slice.length());
SliceOutput output = newSlice.getOutput();
int[] newOffsets = new int[columnData.rowCount() + 1];
for (int row = 0; row < columnData.rowCount(); row++) {
int offset = columnData.getOffset(row);
int length = columnData.getLength(row);
for (int i = 0; i < length; i++) {
byte value = slice.getByte(offset + i);
if (value == escapeByte && i + 1 < length) {
// read byte after escape
i++;
value = slice.getByte(offset + i);
}
output.write(value);
}
newOffsets[row + 1] = output.size();
}
return new ColumnData(newOffsets, output.slice());
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class VariableWidthBlock method copyPositions.
@Override
public Block copyPositions(List<Integer> positions) {
checkValidPositions(positions, positionCount);
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(slice.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 TestSerDeUtils 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