use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class VariableWidthBlock method copyPositions.
@Override
public Block copyPositions(int[] positions, int offset, int length) {
checkArrayRange(positions, offset, length);
int finalLength = 0;
for (int i = offset; i < offset + length; i++) {
finalLength += getSliceLength(positions[i]);
}
SliceOutput newSlice = Slices.allocate(finalLength).getOutput();
int[] newOffsets = new int[length + 1];
boolean[] newValueIsNull = null;
if (valueIsNull != null) {
newValueIsNull = new boolean[length];
}
for (int i = 0; i < length; i++) {
int position = positions[offset + i];
if (!isEntryNull(position)) {
newSlice.writeBytes(slice, getPositionOffset(position), getSliceLength(position));
} else if (newValueIsNull != null) {
newValueIsNull[i] = true;
}
newOffsets[i + 1] = newSlice.size();
}
return new VariableWidthBlock(0, length, newSlice.slice(), newOffsets, newValueIsNull);
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class AbstractTestHiveFileFormats method blockToSlice.
private Slice blockToSlice(Block block) {
// This function is strictly for testing use only
SliceOutput sliceOutput = new DynamicSliceOutput(1000);
BlockSerdeUtil.writeBlock(blockEncodingSerde, sliceOutput, block);
return sliceOutput.slice();
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class PagesResponseWriter method writeTo.
@Override
public void writeTo(List<SerializedPage> serializedPages, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream output) throws IOException, WebApplicationException {
try {
SliceOutput sliceOutput = new OutputStreamSliceOutput(output);
writeSerializedPages(sliceOutput, serializedPages);
// We use flush instead of close, because the underlying stream would be closed and that is not allowed.
sliceOutput.flush();
} catch (UncheckedIOException e) {
// This is not a "server" problem so we don't want to log this
if (!(e.getCause() instanceof EOFException)) {
throw e;
}
}
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class FileFragmentResultCacheManager method cachePages.
private void cachePages(CacheKey key, Path path, List<Page> pages, long resultSize) {
try {
Files.createFile(path);
try (SliceOutput output = new OutputStreamSliceOutput(newOutputStream(path, APPEND))) {
writePages(pagesSerdeFactory.createPagesSerde(), output, pages.iterator());
long resultPhysicalBytes = output.size();
cache.put(key, new CacheEntry(path, resultPhysicalBytes));
fragmentCacheStats.incrementCacheEntries();
fragmentCacheStats.addCacheSizeInBytes(resultPhysicalBytes);
} catch (UncheckedIOException | IOException e) {
log.warn(e, "%s encountered an error while writing to path %s", Thread.currentThread().getName(), path);
tryDeleteFile(path);
}
} catch (UncheckedIOException | IOException e) {
log.warn(e, "%s encountered an error while writing to path %s", Thread.currentThread().getName(), path);
tryDeleteFile(path);
} finally {
fragmentCacheStats.addInFlightBytes(-resultSize);
}
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class TestOrcMetadataReader method concatSlice.
static Slice concatSlice(Slice... slices) {
int totalLength = Arrays.stream(slices).mapToInt(Slice::length).sum();
Slice value = Slices.allocate(totalLength);
SliceOutput output = value.getOutput();
for (Slice slice : slices) {
output.writeBytes(slice);
}
return value;
}
Aggregations