Source:
<code>private PhysicalOperation createLocalMerge(ExchangeNode node, LocalExecutionPlanContext context) { checkState(node.getSources().size() == 1, "single source is expected"); <START> context.setDriverInstanceCount(1); <END> PlanNode sourceNode = getOnlyElement(node.getSources()); LocalExecutionPlanContext subContext = context.createSubContext(); PhysicalOperation source = sourceNode.accept(this, subContext); int operatorsCount = subContext.getDriverInstanceCount().orElse(1); List<Type> types = getSourceOperatorTypes(node, context.getTypes()); LocalExchangeFactory exchangeFactory = new LocalExchangeFactory( node.getPartitioningScheme().getPartitioning().getHandle(), operatorsCount, types, ImmutableList.of(), Optional.empty(), source.getPipelineExecutionStrategy(), maxLocalExchangeBufferSize); List<OperatorFactory> operatorFactories = new ArrayList<>(source.getOperatorFactories()); List<Symbol> expectedLayout = node.getInputs().get(0); Function<Page, Page> pagePreprocessor = enforceLayoutProcessor(expectedLayout, source.getLayout()); operatorFactories.add(new LocalExchangeSinkOperatorFactory( exchangeFactory, subContext.getNextOperatorId(), node.getId(), exchangeFactory.newSinkFactoryId(), pagePreprocessor)); context.addDriverFactory(subContext.isInputDriver(), false, operatorFactories, subContext.getDriverInstanceCount(), source.getPipelineExecutionStrategy()); context.setInputDriver(false); OrderingScheme orderingScheme = node.getOrderingScheme().get(); List<Integer> sortChannels = orderingScheme.getOrderBy().stream() .map(argument -> node.getOutputSymbols().indexOf(argument)) .collect(toImmutableList()); List<SortOrder> orderings = orderingScheme.getOrderBy().stream() .map(orderingScheme::getOrdering) .collect(toImmutableList()); OperatorFactory operatorFactory = new LocalMergeSourceOperatorFactory( context.getNextOperatorId(), node.getId(), new SimplePageWithPositionComparator.Factory(), exchangeFactory, types, sortChannels, orderings); return new PhysicalOperation(operatorFactory, makeLayout(node), context, UNGROUPED_EXECUTION); }</code><technical_language>nit: consider adding checkArgument(node.getOrderingScheme().isPresent(), "orderingScheme is absent"); match createMergeSource</technical_language>

Target:
private PhysicalOperation createLocalMerge(ExchangeNode node, LocalExecutionPlanContext context) { checkArgument(node.getOrderingScheme().isPresent(), "orderingScheme is absent"); checkState(node.getSources().size() == 1, "single source is expected"); context.setDriverInstanceCount(1); PlanNode sourceNode = getOnlyElement(node.getSources()); LocalExecutionPlanContext subContext = context.createSubContext(); PhysicalOperation source = sourceNode.accept(this, subContext); int operatorsCount = subContext.getDriverInstanceCount().orElse(1); List<Type> types = getSourceOperatorTypes(node, context.getTypes()); LocalExchangeFactory exchangeFactory = new LocalExchangeFactory( node.getPartitioningScheme().getPartitioning().getHandle(), operatorsCount, types, ImmutableList.of(), Optional.empty(), source.getPipelineExecutionStrategy(), maxLocalExchangeBufferSize); List<OperatorFactory> operatorFactories = new ArrayList<>(source.getOperatorFactories()); List<Symbol> expectedLayout = node.getInputs().get(0); Function<Page, Page> pagePreprocessor = enforceLayoutProcessor(expectedLayout, source.getLayout()); operatorFactories.add(new LocalExchangeSinkOperatorFactory( exchangeFactory, subContext.getNextOperatorId(), node.getId(), exchangeFactory.newSinkFactoryId(), pagePreprocessor)); context.addDriverFactory(subContext.isInputDriver(), false, operatorFactories, subContext.getDriverInstanceCount(), source.getPipelineExecutionStrategy()); context.setInputDriver(false); OrderingScheme orderingScheme = node.getOrderingScheme().get(); ImmutableMap<Symbol, Integer> layout = makeLayout(node); List<Integer> sortChannels = getChannelsForSymbols(orderingScheme.getOrderBy(), layout); List<SortOrder> orderings = orderingScheme.getOrderingList(); OperatorFactory operatorFactory = new LocalMergeSourceOperatorFactory( context.getNextOperatorId(), node.getId(), exchangeFactory, types, orderingCompiler, sortChannels, orderings); return new PhysicalOperation(operatorFactory, layout, context, UNGROUPED_EXECUTION); }