Search in sources :

Example 1 with PageWithPositionComparator

use of io.prestosql.operator.PageWithPositionComparator 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 2 with PageWithPositionComparator

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

the class OrderingCompiler method generatePageWithPositionComparatorClass.

private Class<? extends PageWithPositionComparator> generatePageWithPositionComparatorClass(List<Type> sortTypes, List<Integer> sortChannels, List<SortOrder> sortOrders) {
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("PageWithPositionComparator"), type(Object.class), type(PageWithPositionComparator.class));
    classDefinition.declareDefaultConstructor(a(PUBLIC));
    generateMergeSortCompareTo(classDefinition, callSiteBinder, sortTypes, sortChannels, sortOrders);
    return defineClass(classDefinition, PageWithPositionComparator.class, callSiteBinder.getBindings(), getClass().getClassLoader());
}
Also used : ClassDefinition(io.airlift.bytecode.ClassDefinition) SimplePageWithPositionComparator(io.prestosql.operator.SimplePageWithPositionComparator) PageWithPositionComparator(io.prestosql.operator.PageWithPositionComparator)

Example 3 with PageWithPositionComparator

use of io.prestosql.operator.PageWithPositionComparator 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)

Aggregations

PageWithPositionComparator (io.prestosql.operator.PageWithPositionComparator)3 SimplePageWithPositionComparator (io.prestosql.operator.SimplePageWithPositionComparator)3 ClassDefinition (io.airlift.bytecode.ClassDefinition)1 AggregatedMemoryContext (io.prestosql.memory.context.AggregatedMemoryContext)1 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)1 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)1 WorkProcessor (io.prestosql.operator.WorkProcessor)1 Page (io.prestosql.spi.Page)1