Search in sources :

Example 1 with SimplePageWithPositionComparator

use of io.prestosql.operator.SimplePageWithPositionComparator in project hetu-core by openlookeng.

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)), 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.prestosql.spi.type.Type) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Page(io.prestosql.spi.Page) SimplePageWithPositionComparator(io.prestosql.operator.SimplePageWithPositionComparator) Test(org.testng.annotations.Test)

Example 2 with SimplePageWithPositionComparator

use of io.prestosql.operator.SimplePageWithPositionComparator in project hetu-core by openlookeng.

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

Example 3 with SimplePageWithPositionComparator

use of io.prestosql.operator.SimplePageWithPositionComparator in project hetu-core by openlookeng.

the class OrderingCompiler method internalCompilePageWithPositionComparator.

private PageWithPositionComparator internalCompilePageWithPositionComparator(List<Type> types, List<Integer> sortChannels, List<SortOrder> sortOrders) {
    PageWithPositionComparator comparator;
    try {
        Class<? extends PageWithPositionComparator> pageWithPositionsComparatorClass = generatePageWithPositionComparatorClass(types, sortChannels, sortOrders);
        comparator = pageWithPositionsComparatorClass.getConstructor().newInstance();
    } catch (Throwable t) {
        log.error(t, "Error compiling comparator for channels %s with order %s", sortChannels, sortChannels);
        comparator = new SimplePageWithPositionComparator(types, sortChannels, sortOrders);
    }
    return comparator;
}
Also used : SimplePageWithPositionComparator(io.prestosql.operator.SimplePageWithPositionComparator) SimplePageWithPositionComparator(io.prestosql.operator.SimplePageWithPositionComparator) PageWithPositionComparator(io.prestosql.operator.PageWithPositionComparator)

Example 4 with SimplePageWithPositionComparator

use of io.prestosql.operator.SimplePageWithPositionComparator in project hetu-core by openlookeng.

the class TestMergeSortedPages method testSortingYields.

@Test
public void testSortingYields() {
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    yieldSignal.forceYieldForTesting();
    List<Type> types = ImmutableList.of(INTEGER);
    WorkProcessor<Page> mergedPages = MergeSortedPages.mergeSortedPages(ImmutableList.of(WorkProcessor.fromIterable(rowPagesBuilder(types).row(1).build())), new SimplePageWithPositionComparator(types, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST)), ImmutableList.of(0), types, (pageBuilder, pageWithPosition) -> pageBuilder.isFull(), false, newSimpleAggregatedMemoryContext().newAggregatedMemoryContext(), yieldSignal);
    // yield signal is on
    assertFalse(mergedPages.process());
    yieldSignal.resetYieldForTesting();
    // page is produced
    assertTrue(mergedPages.process());
    assertFalse(mergedPages.isFinished());
    Page page = mergedPages.getResult();
    MaterializedResult expected = resultBuilder(TEST_SESSION, types).row(1).build();
    assertEquals(toMaterializedResult(TEST_SESSION, types, ImmutableList.of(page)), expected);
    // merge source finished
    assertTrue(mergedPages.process());
    assertTrue(mergedPages.isFinished());
}
Also used : Type(io.prestosql.spi.type.Type) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Page(io.prestosql.spi.Page) SimplePageWithPositionComparator(io.prestosql.operator.SimplePageWithPositionComparator) OperatorAssertion.toMaterializedResult(io.prestosql.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(io.prestosql.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

SimplePageWithPositionComparator (io.prestosql.operator.SimplePageWithPositionComparator)4 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)3 Page (io.prestosql.spi.Page)3 PageWithPositionComparator (io.prestosql.operator.PageWithPositionComparator)2 Type (io.prestosql.spi.type.Type)2 Test (org.testng.annotations.Test)2 AggregatedMemoryContext (io.prestosql.memory.context.AggregatedMemoryContext)1 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)1 OperatorAssertion.toMaterializedResult (io.prestosql.operator.OperatorAssertion.toMaterializedResult)1 WorkProcessor (io.prestosql.operator.WorkProcessor)1 MaterializedResult (io.prestosql.testing.MaterializedResult)1