Source:
<code>private CompletableFuture<List<Row>> retrieveRows(ShardRouting activePrimaryRouting, RoutedCollectPhase collectPhase, CollectTask collectTask, ShardCollectorProviderFactory shardCollectorProviderFactory) { Collector<Row, ?, List<Object[]>> listCollector = Collectors.mapping(Row::materialize, Collectors.toList()); CollectingRowConsumer<?, List<Object[]>> consumer = new CollectingRowConsumer<>(listCollector); String nodeId = activePrimaryRouting.currentNodeId(); String localNodeId = clusterService.localNode().getId(); if (localNodeId.equalsIgnoreCase(nodeId)) { var indexShard = indicesService.indexServiceSafe(activePrimaryRouting.index()) .getShard(activePrimaryRouting.shardId().id()); var collectorProvider = shardCollectorProviderFactory.create(indexShard); BatchIterator<Row> it; try { it = collectorProvider.getIterator(collectPhase, consumer.requiresScroll(), collectTask); } catch (Exception e) { return Exceptions.rethrowRuntimeException(e); } consumer.accept(it, null); } else { UUID childJobId = UUID.randomUUID(); RemoteCollector remoteCollector = new RemoteCollector( childJobId, collectTask.txnCtx().sessionSettings(), localNodeId, nodeId, transportActionProvider.transportJobInitAction(), transportActionProvider.transportKillJobsNodeAction(), searchTp, tasksService, collectTask.getRamAccounting(), consumer, createRemoteCollectPhase(childJobId, collectPhase, activePrimaryRouting.shardId(), nodeId) ); remoteCollector.doCollect(); } return consumer.completionFuture() <START> .thenApply(rows -> Lists2.map(rows, Buckets.arrayToSharedRow()::apply)); <END> }</code><technical_language>Similar mapLazy here</technical_language>

Target:
private CompletableFuture<List<Row>> retrieveRows(ShardRouting activePrimaryRouting, RoutedCollectPhase collectPhase, CollectTask collectTask, ShardCollectorProviderFactory shardCollectorProviderFactory) { Collector<Row, ?, List<Object[]>> listCollector = Collectors.mapping(Row::materialize, Collectors.toList()); CollectingRowConsumer<?, List<Object[]>> consumer = new CollectingRowConsumer<>(listCollector); String nodeId = activePrimaryRouting.currentNodeId(); String localNodeId = clusterService.localNode().getId(); if (localNodeId.equalsIgnoreCase(nodeId)) { var indexShard = indicesService.indexServiceSafe(activePrimaryRouting.index()) .getShard(activePrimaryRouting.shardId().id()); var collectorProvider = shardCollectorProviderFactory.create(indexShard); BatchIterator<Row> it; try { it = collectorProvider.getIterator(collectPhase, consumer.requiresScroll(), collectTask); } catch (Exception e) { return Exceptions.rethrowRuntimeException(e); } consumer.accept(it, null); } else { UUID childJobId = UUID.randomUUID(); RemoteCollector remoteCollector = new RemoteCollector( childJobId, collectTask.txnCtx().sessionSettings(), localNodeId, nodeId, transportActionProvider.transportJobInitAction(), transportActionProvider.transportKillJobsNodeAction(), searchTp, tasksService, collectTask.getRamAccounting(), consumer, createRemoteCollectPhase(childJobId, collectPhase, activePrimaryRouting.shardId(), nodeId) ); remoteCollector.doCollect(); } return consumer .completionFuture() .thenApply(rows -> LazyMapList.of(rows, Buckets.arrayToSharedRow())); }