Search in sources :

Example 6 with DynamicSliceOutput

use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.

the class FixedWidthBlockBuilder method reset.

@Override
public void reset(BlockBuilderStatus blockBuilderStatus) {
    this.blockBuilderStatus = requireNonNull(blockBuilderStatus, "blockBuilderStatus is null");
    int newSize = calculateBlockResetSize(positionCount);
    valueIsNull = new DynamicSliceOutput(newSize);
    sliceOutput = new DynamicSliceOutput(newSize * getFixedSize());
    positionCount = 0;
    currentEntrySize = 0;
}
Also used : DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput)

Example 7 with DynamicSliceOutput

use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.

the class PagesSerde method serialize.

public SerializedPage serialize(Page page) {
    // block length is an int
    SliceOutput serializationBuffer = new DynamicSliceOutput(toIntExact((page.getSizeInBytes() + Integer.BYTES)));
    writeRawPage(page, serializationBuffer, blockEncodingSerde);
    if (!compressor.isPresent()) {
        return new SerializedPage(serializationBuffer.slice(), UNCOMPRESSED, page.getPositionCount(), serializationBuffer.size());
    }
    int maxCompressedLength = maxCompressedLength(serializationBuffer.size());
    byte[] compressionBuffer = new byte[maxCompressedLength];
    int actualCompressedLength = compressor.get().compress(serializationBuffer.slice().getBytes(), 0, serializationBuffer.size(), compressionBuffer, 0, maxCompressedLength);
    if (((1.0 * actualCompressedLength) / serializationBuffer.size()) > MINIMUM_COMPRESSION_RATIO) {
        return new SerializedPage(serializationBuffer.slice(), UNCOMPRESSED, page.getPositionCount(), serializationBuffer.size());
    }
    return new SerializedPage(Slices.copyOf(Slices.wrappedBuffer(compressionBuffer, 0, actualCompressedLength)), COMPRESSED, page.getPositionCount(), serializationBuffer.size());
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput)

Example 8 with DynamicSliceOutput

use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.

the class JsonFunctions method jsonParse.

@ScalarFunction
@LiteralParameters("x")
@SqlType(StandardTypes.JSON)
public static Slice jsonParse(@SqlType("varchar(x)") Slice slice) {
    try {
        byte[] in = slice.getBytes();
        SliceOutput dynamicSliceOutput = new DynamicSliceOutput(in.length);
        SORTED_MAPPER.writeValue((OutputStream) dynamicSliceOutput, SORTED_MAPPER.readValue(in, Object.class));
        return dynamicSliceOutput.slice();
    } catch (Exception e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Cannot convert '%s' to JSON", slice.toStringUtf8()));
    }
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) PrestoException(com.facebook.presto.spi.PrestoException) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) LiteralParameters(com.facebook.presto.spi.function.LiteralParameters) SqlType(com.facebook.presto.spi.function.SqlType)

Example 9 with DynamicSliceOutput

use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.

the class AbstractTestBlock method copyBlock.

private static Block copyBlock(Block block) {
    DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024);
    BlockEncoding blockEncoding = block.getEncoding();
    blockEncoding.writeBlock(sliceOutput, block);
    return blockEncoding.readBlock(sliceOutput.slice().getInput());
}
Also used : DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) BlockEncoding(com.facebook.presto.spi.block.BlockEncoding)

Example 10 with DynamicSliceOutput

use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.

the class TestPagesSerde method serializedSize.

private static int serializedSize(List<? extends Type> types, Page expectedPage) {
    PagesSerde serde = new TestingPagesSerdeFactory().createPagesSerde();
    DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024);
    writePages(serde, sliceOutput, expectedPage);
    Slice slice = sliceOutput.slice();
    Iterator<Page> pageIterator = readPages(serde, slice.getInput());
    if (pageIterator.hasNext()) {
        assertPageEquals(types, pageIterator.next(), expectedPage);
    } else {
        assertEquals(expectedPage.getPositionCount(), 0);
    }
    assertFalse(pageIterator.hasNext());
    return slice.length();
}
Also used : Slice(io.airlift.slice.Slice) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) Page(com.facebook.presto.spi.Page)

Aggregations

DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)24 SliceOutput (io.airlift.slice.SliceOutput)9 Test (org.testng.annotations.Test)8 Block (com.facebook.presto.spi.block.Block)5 Slice (io.airlift.slice.Slice)4 BlockSerdeUtil.writeBlock (com.facebook.presto.block.BlockSerdeUtil.writeBlock)3 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)3 Page (com.facebook.presto.spi.Page)2 PrestoException (com.facebook.presto.spi.PrestoException)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 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)1 BufferResult (com.facebook.presto.execution.buffer.BufferResult)1 Signature (com.facebook.presto.metadata.Signature)1 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)1 BlockEncoding (com.facebook.presto.spi.block.BlockEncoding)1 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)1 Description (com.facebook.presto.spi.function.Description)1 Type (com.facebook.presto.spi.type.Type)1