use of io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class TestPageProcessorCompiler method testSanityRLE.
@Test
public void testSanityRLE() {
PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(field(0, BIGINT), field(1, VARCHAR)), MAX_BATCH_SIZE).get();
Slice varcharValue = Slices.utf8Slice("hello");
Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 123L, 100), RunLengthEncodedBlock.create(VARCHAR, varcharValue, 100));
Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
assertEquals(outputPage.getPositionCount(), 100);
assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
assertTrue(outputPage.getBlock(1) instanceof RunLengthEncodedBlock);
RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) outputPage.getBlock(0);
assertEquals(BIGINT.getLong(rleBlock.getValue(), 0), 123L);
RunLengthEncodedBlock rleBlock1 = (RunLengthEncodedBlock) outputPage.getBlock(1);
assertEquals(VARCHAR.getSlice(rleBlock1.getValue(), 0), varcharValue);
}
use of io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class ArgumentComputation method compute.
public Block compute(Block[] blocks) {
// wrap block array into a single-row page
Page page = new Page(1, blocks);
// evaluate expression
Work<Block> work = projection.project(session, new DriverYieldSignal(), projection.getInputChannels().getInputChannels(page), positionsRange(0, 1));
boolean done = false;
while (!done) {
done = work.process();
}
return work.getResult();
}
use of io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class BenchmarkPagesSort method runPagesMergeSortBenchmark.
@Benchmark
public List<Page> runPagesMergeSortBenchmark(MergeSortedBenchmarkData data) {
WorkProcessor<Page> sortedPagesWork = mergeSortedPages(data.getSplitPages().stream().map(WorkProcessor::fromIterable).collect(toImmutableList()), ORDERING_COMPILER.compilePageWithPositionComparator(data.getSortTypes(), data.getSortChannels(), data.getSortOrders()), data.getOutputChannels(), data.getTypes(), (pageBuilder, pageWithPosition) -> pageBuilder.isFull(), false, newSimpleAggregatedMemoryContext(), new DriverYieldSignal());
ImmutableList.Builder<Page> sortedPages = ImmutableList.builder();
while (true) {
sortedPagesWork.process();
if (sortedPagesWork.isFinished()) {
return sortedPages.build();
}
sortedPages.add(sortedPagesWork.getResult());
}
}
use of io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class TestMergeSortedPages method testMergeSortYieldingProgresses.
@Test
public void testMergeSortYieldingProgresses() {
DriverYieldSignal yieldSignal = new DriverYieldSignal();
yieldSignal.forceYieldForTesting();
List<Type> types = ImmutableList.of(INTEGER);
WorkProcessor<Page> mergedPages = MergeSortedPages.mergeSortedPages(ImmutableList.of(WorkProcessor.fromIterable(rowPagesBuilder(types).build())), new SimplePageWithPositionComparator(types, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST), TYPE_OPERATORS_CACHE), ImmutableList.of(0), types, (pageBuilder, pageWithPosition) -> pageBuilder.isFull(), false, newSimpleAggregatedMemoryContext().newAggregatedMemoryContext(), yieldSignal);
// yield signal is on
assertFalse(mergedPages.process());
// processor finishes computations (yield signal is still on, but previous process() call yielded)
assertTrue(mergedPages.process());
assertTrue(mergedPages.isFinished());
}
use of io.trino.operator.DriverYieldSignal in project trino by trinodb.
the class TestMergeSortedPages method mergeSortedPages.
private static MaterializedResult mergeSortedPages(List<Type> types, List<Integer> sortChannels, List<SortOrder> sortOrder, List<List<Page>> sortedPages) {
List<WorkProcessor<Page>> pageProducers = sortedPages.stream().map(WorkProcessor::fromIterable).collect(toImmutableList());
PageWithPositionComparator comparator = new SimplePageWithPositionComparator(types, sortChannels, sortOrder, TYPE_OPERATORS_CACHE);
AggregatedMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newAggregatedMemoryContext();
WorkProcessor<Page> mergedPages = MergeSortedPages.mergeSortedPages(pageProducers, comparator, types, memoryContext, new DriverYieldSignal());
assertTrue(mergedPages.process());
if (mergedPages.isFinished()) {
return toMaterializedResult(TEST_SESSION, types, ImmutableList.of());
}
Page page = mergedPages.getResult();
assertTrue(mergedPages.process());
assertTrue(mergedPages.isFinished());
assertEquals(memoryContext.getBytes(), 0L);
return toMaterializedResult(TEST_SESSION, types, ImmutableList.of(page));
}
Aggregations