use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.
the class AbstractTestBlock method createGreaterValue.
private static Slice createGreaterValue(Slice expectedValue, int offset, int length) {
DynamicSliceOutput greaterOutput = new DynamicSliceOutput(length + 1);
greaterOutput.writeBytes(expectedValue, offset, length);
greaterOutput.writeByte('_');
return greaterOutput.slice();
}
use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.
the class AbstractTestHiveFileFormats 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();
}
use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.
the class ParquetCompressionUtils method decompressGzip.
private static Slice decompressGzip(Slice input, int uncompressedSize) throws IOException {
if (uncompressedSize == 0) {
return EMPTY_SLICE;
}
DynamicSliceOutput sliceOutput = new DynamicSliceOutput(uncompressedSize);
byte[] buffer = new byte[uncompressedSize];
try (InputStream gzipInputStream = new GZIPInputStream(input.getInput(), GZIP_BUFFER_SIZE)) {
int bytesRead;
while ((bytesRead = gzipInputStream.read(buffer)) != -1) {
sliceOutput.write(buffer, 0, bytesRead);
}
return sliceOutput.getUnderlyingSlice();
}
}
use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.
the class JoniRegexpFunctions method regexpReplace.
@Description("replaces substrings matching a regular expression by given string")
@ScalarFunction
@LiteralParameters({ "x", "y", "z" })
// to get the formula: x + max(x * y / 2, y) * (x + 1)
@Constraint(variable = "z", expression = "min(2147483647, x + max(x * y / 2, y) * (x + 1))")
@SqlType("varchar(z)")
public static Slice regexpReplace(@SqlType("varchar(x)") Slice source, @SqlType(JoniRegexpType.NAME) Regex pattern, @SqlType("varchar(y)") Slice replacement) {
Matcher matcher = pattern.matcher(source.getBytes());
SliceOutput sliceOutput = new DynamicSliceOutput(source.length() + replacement.length() * 5);
int lastEnd = 0;
// nextStart is the same as lastEnd, unless the last match was zero-width. In such case, nextStart is lastEnd + 1.
int nextStart = 0;
while (true) {
int offset = matcher.search(nextStart, source.length(), Option.DEFAULT);
if (offset == -1) {
break;
}
if (matcher.getEnd() == matcher.getBegin()) {
nextStart = matcher.getEnd() + 1;
} else {
nextStart = matcher.getEnd();
}
Slice sliceBetweenReplacements = source.slice(lastEnd, matcher.getBegin() - lastEnd);
lastEnd = matcher.getEnd();
sliceOutput.appendBytes(sliceBetweenReplacements);
appendReplacement(sliceOutput, source, pattern, matcher.getEagerRegion(), replacement);
}
sliceOutput.appendBytes(source.slice(lastEnd, source.length() - lastEnd));
return sliceOutput.slice();
}
use of io.airlift.slice.DynamicSliceOutput in project presto by prestodb.
the class MockExchangeRequestProcessor method handle.
@Override
public Response handle(Request request) throws Exception {
if (request.getMethod().equalsIgnoreCase("DELETE")) {
return new TestingResponse(HttpStatus.NO_CONTENT, ImmutableListMultimap.of(), new byte[0]);
}
// verify we got a data size and it parses correctly
assertTrue(!request.getHeaders().get(PrestoHeaders.PRESTO_MAX_SIZE).isEmpty());
DataSize maxSize = DataSize.valueOf(request.getHeader(PrestoHeaders.PRESTO_MAX_SIZE));
assertEquals(maxSize, expectedMaxSize);
RequestLocation requestLocation = new RequestLocation(request.getUri());
URI location = requestLocation.getLocation();
BufferResult result = buffers.getUnchecked(location).getPages(requestLocation.getSequenceId(), maxSize);
byte[] bytes = new byte[0];
HttpStatus status;
if (!result.getSerializedPages().isEmpty()) {
DynamicSliceOutput sliceOutput = new DynamicSliceOutput(64);
PagesSerdeUtil.writeSerializedPages(sliceOutput, result.getSerializedPages());
bytes = sliceOutput.slice().getBytes();
status = HttpStatus.OK;
} else {
status = HttpStatus.NO_CONTENT;
}
return new TestingResponse(status, ImmutableListMultimap.of(CONTENT_TYPE, PRESTO_PAGES, PRESTO_TASK_INSTANCE_ID, String.valueOf(result.getTaskInstanceId()), PRESTO_PAGE_TOKEN, String.valueOf(result.getToken()), PRESTO_PAGE_NEXT_TOKEN, String.valueOf(result.getNextToken()), PRESTO_BUFFER_COMPLETE, String.valueOf(result.isBufferComplete())), bytes);
}
Aggregations