Search in sources :

Example 6 with SliceOutput

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);
    }
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) Slice(io.airlift.slice.Slice) Test(org.testng.annotations.Test)

Example 7 with SliceOutput

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);
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) Test(org.testng.annotations.Test)

Example 8 with SliceOutput

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());
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) Slice(io.airlift.slice.Slice) ColumnData(com.facebook.presto.rcfile.ColumnData)

Example 9 with SliceOutput

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);
}
Also used : SliceOutput(io.airlift.slice.SliceOutput)

Example 10 with SliceOutput

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();
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput)

Aggregations

SliceOutput (io.airlift.slice.SliceOutput)21 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)11 Slice (io.airlift.slice.Slice)9 Test (org.testng.annotations.Test)3 Block (com.facebook.presto.spi.block.Block)2 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)2 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)2 SqlType (com.facebook.presto.spi.function.SqlType)2 BlockSerdeUtil.writeBlock (com.facebook.presto.block.BlockSerdeUtil.writeBlock)1 Signature (com.facebook.presto.metadata.Signature)1 ColumnData (com.facebook.presto.rcfile.ColumnData)1 PrestoException (com.facebook.presto.spi.PrestoException)1 Description (com.facebook.presto.spi.function.Description)1 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)1 VarcharType (com.facebook.presto.spi.type.VarcharType)1 ArithmeticUnaryExpression (com.facebook.presto.sql.tree.ArithmeticUnaryExpression)1 BooleanLiteral (com.facebook.presto.sql.tree.BooleanLiteral)1 Cast (com.facebook.presto.sql.tree.Cast)1 DoubleLiteral (com.facebook.presto.sql.tree.DoubleLiteral)1 Expression (com.facebook.presto.sql.tree.Expression)1