use of io.crate.execution.engine.pipeline.ProjectorFactory in project crate by crate.
the class PKLookupOperation method lookup.
public BatchIterator<Row> lookup(UUID jobId, TransactionContext txnCtx, Supplier<RamAccounting> ramAccountingSupplier, Supplier<MemoryManager> memoryManagerSupplier, boolean ignoreMissing, Map<ShardId, List<PKAndVersion>> idsByShard, Collection<? extends Projection> projections, boolean requiresScroll, Function<Doc, Row> resultToRow) {
ArrayList<BatchIterator<Row>> iterators = new ArrayList<>(idsByShard.size());
for (Map.Entry<ShardId, List<PKAndVersion>> idsByShardEntry : idsByShard.entrySet()) {
ShardId shardId = idsByShardEntry.getKey();
IndexService indexService = indicesService.indexService(shardId.getIndex());
if (indexService == null) {
if (ignoreMissing) {
continue;
}
throw new IndexNotFoundException(shardId.getIndex());
}
IndexShard shard = indexService.getShardOrNull(shardId.id());
if (shard == null) {
if (ignoreMissing) {
continue;
}
throw new ShardNotFoundException(shardId);
}
Stream<Row> rowStream = idsByShardEntry.getValue().stream().map(pkAndVersion -> lookupDoc(shard, pkAndVersion.id(), pkAndVersion.version(), VersionType.EXTERNAL, pkAndVersion.seqNo(), pkAndVersion.primaryTerm())).filter(Objects::nonNull).map(resultToRow);
if (projections.isEmpty()) {
final Iterable<Row> rowIterable = requiresScroll ? rowStream.map(row -> new RowN(row.materialize())).collect(Collectors.toList()) : rowStream::iterator;
iterators.add(InMemoryBatchIterator.of(rowIterable, SentinelRow.SENTINEL, true));
} else {
ProjectorFactory projectorFactory;
try {
projectorFactory = shardCollectSource.getProjectorFactory(shardId);
} catch (ShardNotFoundException e) {
if (ignoreMissing) {
continue;
}
throw e;
}
Projectors projectors = new Projectors(projections, jobId, txnCtx, ramAccountingSupplier.get(), memoryManagerSupplier.get(), projectorFactory);
final Iterable<Row> rowIterable = requiresScroll && !projectors.providesIndependentScroll() ? rowStream.map(row -> new RowN(row.materialize())).collect(Collectors.toList()) : rowStream::iterator;
iterators.add(projectors.wrap(InMemoryBatchIterator.of(rowIterable, SentinelRow.SENTINEL, true)));
}
}
// noinspection unchecked
return CompositeBatchIterator.seqComposite(iterators.toArray(new BatchIterator[0]));
}
Aggregations