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