Search in sources :

Example 1 with CollectingBatchIterator

use of io.crate.data.CollectingBatchIterator in project crate by crate.

the class SystemCollectSource method getIterator.

@Override
public CompletableFuture<BatchIterator<Row>> getIterator(TransactionContext txnCtx, CollectPhase phase, CollectTask collectTask, boolean supportMoveToStart) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    Map<String, Map<String, IntIndexedContainer>> locations = collectPhase.routing().locations();
    String table = Iterables.getOnlyElement(locations.get(clusterService.localNode().getId()).keySet());
    RelationName relationName = RelationName.fromIndexName(table);
    StaticTableDefinition<?> tableDefinition = tableDefinition(relationName);
    User user = requireNonNull(userLookup.findUser(txnCtx.sessionSettings().userName()), "User who invoked a statement must exist");
    return CompletableFuture.completedFuture(CollectingBatchIterator.newInstance(() -> {
    }, // If data is already local, then `CollectingBatchIterator` takes care of kill handling.
    t -> {
    }, () -> tableDefinition.retrieveRecords(txnCtx, user).thenApply(records -> recordsToRows(collectPhase, collectTask.txnCtx(), tableDefinition.getReferenceResolver(), supportMoveToStart, records)), tableDefinition.involvesIO()));
}
Also used : UserLookup(io.crate.user.UserLookup) TransactionContext(io.crate.metadata.TransactionContext) InformationSchemaTableDefinitions(io.crate.metadata.information.InformationSchemaTableDefinitions) RelationName(io.crate.metadata.RelationName) ClusterService(org.elasticsearch.cluster.service.ClusterService) BatchIterator(io.crate.data.BatchIterator) ReferenceResolver(io.crate.expression.reference.ReferenceResolver) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) PgCatalogSchemaInfo(io.crate.metadata.pgcatalog.PgCatalogSchemaInfo) SysRowUpdater(io.crate.expression.reference.sys.SysRowUpdater) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) SysNodeChecks(io.crate.expression.reference.sys.check.node.SysNodeChecks) SchemaUnknownException(io.crate.exceptions.SchemaUnknownException) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) PgCatalogTableDefinitions(io.crate.metadata.pgcatalog.PgCatalogTableDefinitions) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) NodeContext(io.crate.metadata.NodeContext) User(io.crate.user.User) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) RowsTransformer(io.crate.execution.engine.collect.RowsTransformer) StaticTableDefinition(io.crate.expression.reference.StaticTableDefinition) Iterables(io.crate.common.collections.Iterables) CollectingBatchIterator(io.crate.data.CollectingBatchIterator) CollectTask(io.crate.execution.engine.collect.CollectTask) SysNodeChecksTableInfo(io.crate.metadata.sys.SysNodeChecksTableInfo) Row(io.crate.data.Row) SysTableDefinitions(io.crate.metadata.sys.SysTableDefinitions) UserManager(io.crate.user.UserManager) InputFactory(io.crate.expression.InputFactory) RelationUnknown(io.crate.exceptions.RelationUnknown) User(io.crate.user.User) RelationName(io.crate.metadata.RelationName) Map(java.util.Map) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Aggregations

IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)1 Iterables (io.crate.common.collections.Iterables)1 BatchIterator (io.crate.data.BatchIterator)1 CollectingBatchIterator (io.crate.data.CollectingBatchIterator)1 Row (io.crate.data.Row)1 RelationUnknown (io.crate.exceptions.RelationUnknown)1 SchemaUnknownException (io.crate.exceptions.SchemaUnknownException)1 CollectPhase (io.crate.execution.dsl.phases.CollectPhase)1 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)1 CollectTask (io.crate.execution.engine.collect.CollectTask)1 RowsTransformer (io.crate.execution.engine.collect.RowsTransformer)1 InputFactory (io.crate.expression.InputFactory)1 ReferenceResolver (io.crate.expression.reference.ReferenceResolver)1 StaticTableDefinition (io.crate.expression.reference.StaticTableDefinition)1 SysRowUpdater (io.crate.expression.reference.sys.SysRowUpdater)1 SysNodeChecks (io.crate.expression.reference.sys.check.node.SysNodeChecks)1 NodeContext (io.crate.metadata.NodeContext)1 RelationName (io.crate.metadata.RelationName)1 TransactionContext (io.crate.metadata.TransactionContext)1 InformationSchemaInfo (io.crate.metadata.information.InformationSchemaInfo)1