@Override public SourceOperator createOperator(DriverContext driverContext) { checkState(!closed, "Factory is already closed"); OperatorContext operatorContext = driverContext.addOperatorContext(operatorId, sourceId, MergeOperator.class.getSimpleName()); return new MergeOperator( operatorContext, sourceId, exchangeClientSupplier, serdeFactory.createPagesSerde(), orderingCompiler.compilePageWithPositionComparator(types, sortChannels, sortOrder), outputChannels, outputTypes); }
@Override public Operator createOperator(DriverContext driverContext) { checkState(!closed, "Factory is already closed"); LocalExchange localExchange = localExchangeFactory.getLocalExchange(driverContext.getLifespan()); OperatorContext operatorContext = driverContext.addOperatorContext(operatorId, planNodeId, LocalMergeSourceOperator.class.getSimpleName()); PageWithPositionComparator comparator = orderingCompiler.compilePageWithPositionComparator(types, sortChannels, orderings); List<LocalExchangeSource> sources = IntStream.range(0, localExchange.getBufferCount()) .boxed() .map(index -> localExchange.getNextSource()) .collect(toImmutableList()); return new LocalMergeSourceOperator(operatorContext, sources, types, comparator); }
@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()); } }