Search in sources :

Example 16 with DriverYieldSignal

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);
}
Also used : PageProcessor(io.trino.operator.project.PageProcessor) Slice(io.airlift.slice.Slice) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 17 with DriverYieldSignal

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();
}
Also used : Block(io.trino.spi.block.Block) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page)

Example 18 with DriverYieldSignal

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());
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) WorkProcessor(io.trino.operator.WorkProcessor) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) SequencePageBuilder.createSequencePage(io.trino.SequencePageBuilder.createSequencePage) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 19 with DriverYieldSignal

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());
}
Also used : Type(io.trino.spi.type.Type) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) SimplePageWithPositionComparator(io.trino.operator.SimplePageWithPositionComparator) Test(org.testng.annotations.Test)

Example 20 with DriverYieldSignal

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));
}
Also used : WorkProcessor(io.trino.operator.WorkProcessor) DriverYieldSignal(io.trino.operator.DriverYieldSignal) SimplePageWithPositionComparator(io.trino.operator.SimplePageWithPositionComparator) Page(io.trino.spi.Page) PageWithPositionComparator(io.trino.operator.PageWithPositionComparator) SimplePageWithPositionComparator(io.trino.operator.SimplePageWithPositionComparator) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.trino.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) AggregatedMemoryContext(io.trino.memory.context.AggregatedMemoryContext)

Aggregations

DriverYieldSignal (io.trino.operator.DriverYieldSignal)31 Page (io.trino.spi.Page)29 Test (org.testng.annotations.Test)21 Block (io.trino.spi.block.Block)12 LazyBlock (io.trino.spi.block.LazyBlock)10 Optional (java.util.Optional)10 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)7 PageProcessor (io.trino.operator.project.PageProcessor)7 DictionaryBlock (io.trino.spi.block.DictionaryBlock)7 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)6 LocalMemoryContext (io.trino.memory.context.LocalMemoryContext)5 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)4 LongArrayBlock (io.trino.spi.block.LongArrayBlock)4 Type (io.trino.spi.type.Type)4 CallExpression (io.trino.sql.relational.CallExpression)4 Slice (io.airlift.slice.Slice)3 BlockAssertions.createLongDictionaryBlock (io.trino.block.BlockAssertions.createLongDictionaryBlock)3 ResolvedFunction (io.trino.metadata.ResolvedFunction)3 SimplePageWithPositionComparator (io.trino.operator.SimplePageWithPositionComparator)3 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)3