Search in sources :

Example 1 with PageWithPositionComparator

use of com.facebook.presto.operator.PageWithPositionComparator 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 PageWithPositionComparator

use of com.facebook.presto.operator.PageWithPositionComparator 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 PageWithPositionComparator

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

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

Aggregations

PageWithPositionComparator (com.facebook.presto.operator.PageWithPositionComparator)3 SimplePageWithPositionComparator (com.facebook.presto.operator.SimplePageWithPositionComparator)3 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)1 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)1 Page (com.facebook.presto.common.Page)1 AggregatedMemoryContext (com.facebook.presto.memory.context.AggregatedMemoryContext)1 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)1 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)1 WorkProcessor (com.facebook.presto.operator.WorkProcessor)1