Search in sources :

Example 1 with SimplePageWithPositionComparator

use of com.facebook.presto.operator.SimplePageWithPositionComparator in project presto by prestodb.

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(com.facebook.presto.operator.SimplePageWithPositionComparator) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) PageWithPositionComparator(com.facebook.presto.operator.PageWithPositionComparator)

Example 2 with SimplePageWithPositionComparator

use of com.facebook.presto.operator.SimplePageWithPositionComparator in project presto by prestodb.

the class TestMergeSortedPages method mergeSortedPages.

private static MaterializedResult mergeSortedPages(List<Type> types, List<Integer> sortChannels, List<SortOrder> sortOrder, List<List<Page>> sortedPages) throws Exception {
    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(com.facebook.presto.operator.WorkProcessor) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) Page(com.facebook.presto.common.Page) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) PageWithPositionComparator(com.facebook.presto.operator.PageWithPositionComparator) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) AggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext)

Example 3 with SimplePageWithPositionComparator

use of com.facebook.presto.operator.SimplePageWithPositionComparator in project presto by prestodb.

the class TestMergeSortedPages method testMergeSortYieldingProgresses.

@Test
public void testMergeSortYieldingProgresses() throws Exception {
    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(com.facebook.presto.common.type.Type) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) Test(org.testng.annotations.Test)

Example 4 with SimplePageWithPositionComparator

use of com.facebook.presto.operator.SimplePageWithPositionComparator in project presto by prestodb.

the class TestMergeSortedPages method testSortingYields.

@Test
public void testSortingYields() throws Exception {
    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(com.facebook.presto.common.type.Type) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

SimplePageWithPositionComparator (com.facebook.presto.operator.SimplePageWithPositionComparator)4 Page (com.facebook.presto.common.Page)3 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)3 Type (com.facebook.presto.common.type.Type)2 PageWithPositionComparator (com.facebook.presto.operator.PageWithPositionComparator)2 Test (org.testng.annotations.Test)2 AggregatedMemoryContext (com.facebook.presto.memory.context.AggregatedMemoryContext)1 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)1 OperatorAssertion.toMaterializedResult (com.facebook.presto.operator.OperatorAssertion.toMaterializedResult)1 WorkProcessor (com.facebook.presto.operator.WorkProcessor)1 MaterializedResult (com.facebook.presto.testing.MaterializedResult)1