Search in sources :

Example 16 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class RemoteCollectorFactory method createCollector.

/**
     * create a RemoteCollector
     * The RemoteCollector will collect data from another node using a wormhole as if it was collecting on this node.
     * <p>
     * This should only be used if a shard is not available on the current node due to a relocation
     */
public CrateCollector.Builder createCollector(String index, Integer shardId, RoutedCollectPhase collectPhase, final RamAccountingContext ramAccountingContext) {
    // new job because subContexts can't be merged into an existing job
    final UUID childJobId = UUID.randomUUID();
    IndexShardRoutingTable shardRoutings = clusterService.state().routingTable().shardRoutingTable(index, shardId);
    // for update operations primaryShards must be used
    // (for others that wouldn't be the case, but at this point it is not easily visible which is the case)
    ShardRouting shardRouting = shardRoutings.primaryShard();
    final String remoteNodeId = shardRouting.currentNodeId();
    assert remoteNodeId != null : "primaryShard not assigned :(";
    final String localNodeId = clusterService.localNode().getId();
    final RoutedCollectPhase newCollectPhase = createNewCollectPhase(childJobId, collectPhase, index, shardId, remoteNodeId);
    return consumer -> new RemoteCollector(childJobId, localNodeId, remoteNodeId, transportActionProvider.transportJobInitAction(), transportActionProvider.transportKillJobsNodeAction(), jobContextService, ramAccountingContext, consumer, newCollectPhase);
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) java.util(java.util) Projections(io.crate.planner.projection.Projections) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Inject(org.elasticsearch.common.inject.Inject) TreeMapBuilder(io.crate.core.collections.TreeMapBuilder) Routing(io.crate.metadata.Routing) Singleton(org.elasticsearch.common.inject.Singleton) ClusterService(org.elasticsearch.cluster.ClusterService) JobContextService(io.crate.jobs.JobContextService) TransportActionProvider(io.crate.executor.transport.TransportActionProvider) DistributionInfo(io.crate.planner.distribution.DistributionInfo) RamAccountingContext(io.crate.breaker.RamAccountingContext) RemoteCollector(io.crate.operation.collect.collectors.RemoteCollector) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RemoteCollector(io.crate.operation.collect.collectors.RemoteCollector) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 17 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class SystemCollectSource method getCollector.

@Override
public CrateCollector getCollector(CollectPhase phase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    // sys.operations can contain a _node column - these refs need to be normalized into literals
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.DOC, ReplaceMode.COPY, new NodeSysReferenceResolver(nodeSysExpression), null);
    final RoutedCollectPhase routedCollectPhase = collectPhase.normalize(normalizer, null);
    Map<String, Map<String, List<Integer>>> locations = collectPhase.routing().locations();
    String table = Iterables.getOnlyElement(locations.get(clusterService.localNode().getId()).keySet());
    Supplier<CompletableFuture<? extends Iterable<?>>> iterableGetter = iterableGetters.get(table);
    assert iterableGetter != null : "iterableGetter for " + table + " must exist";
    boolean requiresScroll = consumer.requiresScroll();
    return BatchIteratorCollectorBridge.newInstance(() -> iterableGetter.get().thenApply(dataIterable -> RowsBatchIterator.newInstance(dataIterableToRowsIterable(routedCollectPhase, requiresScroll, dataIterable), collectPhase.toCollect().size())), consumer);
}
Also used : BatchIteratorCollectorBridge(io.crate.operation.collect.BatchIteratorCollectorBridge) Iterables(com.google.common.collect.Iterables) CompletableFuture(java.util.concurrent.CompletableFuture) ReplaceMode(io.crate.metadata.ReplaceMode) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Inject(org.elasticsearch.common.inject.Inject) JobCollectContext(io.crate.operation.collect.JobCollectContext) SysSnapshots(io.crate.operation.reference.sys.snapshot.SysSnapshots) ImmutableList(com.google.common.collect.ImmutableList) Functions(io.crate.metadata.Functions) BatchConsumer(io.crate.data.BatchConsumer) io.crate.metadata.sys(io.crate.metadata.sys) NodeSysReferenceResolver(io.crate.operation.reference.sys.node.local.NodeSysReferenceResolver) ClusterService(org.elasticsearch.cluster.ClusterService) Map(java.util.Map) SysRowUpdater(io.crate.operation.reference.sys.SysRowUpdater) SysRepositoriesService(io.crate.operation.reference.sys.repositories.SysRepositoriesService) RowsBatchIterator(io.crate.data.RowsBatchIterator) CrateCollector(io.crate.operation.collect.CrateCollector) SysCheck(io.crate.operation.reference.sys.check.SysCheck) ImmutableMap(com.google.common.collect.ImmutableMap) RowsTransformer(io.crate.operation.collect.RowsTransformer) Set(java.util.Set) SysChecker(io.crate.operation.reference.sys.check.SysChecker) TableIdent(io.crate.metadata.TableIdent) RowContextReferenceResolver(io.crate.operation.reference.sys.RowContextReferenceResolver) JobsLogs(io.crate.operation.collect.stats.JobsLogs) CollectPhase(io.crate.planner.node.dql.CollectPhase) PgCatalogTables(io.crate.metadata.pg_catalog.PgCatalogTables) InputFactory(io.crate.operation.InputFactory) SysNodeChecks(io.crate.operation.reference.sys.check.node.SysNodeChecks) io.crate.metadata.information(io.crate.metadata.information) SummitsIterable(io.crate.operation.collect.files.SummitsIterable) List(java.util.List) RowGranularity(io.crate.metadata.RowGranularity) Row(io.crate.data.Row) NodeSysExpression(io.crate.operation.reference.sys.node.local.NodeSysExpression) PgTypeTable(io.crate.metadata.pg_catalog.PgTypeTable) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) CompletableFuture(java.util.concurrent.CompletableFuture) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) SummitsIterable(io.crate.operation.collect.files.SummitsIterable) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) NodeSysReferenceResolver(io.crate.operation.reference.sys.node.local.NodeSysReferenceResolver)

Example 18 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class DeleteStatementPlanner method collectWithDeleteProjection.

private static Plan collectWithDeleteProjection(TableInfo tableInfo, WhereClause whereClause, Planner.Context plannerContext) {
    // for delete, we always need to collect the `_uid`
    Reference idReference = tableInfo.getReference(DocSysColumns.ID);
    DeleteProjection deleteProjection = new DeleteProjection(new InputColumn(0, DataTypes.STRING));
    Routing routing = plannerContext.allocateRouting(tableInfo, whereClause, Preference.PRIMARY.type());
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), ImmutableList.of(idReference), ImmutableList.of(deleteProjection), whereClause, DistributionInfo.DEFAULT_BROADCAST);
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, 1, 1, null);
    return Merge.ensureOnHandler(collect, plannerContext, Collections.singletonList(MergeCountProjection.INSTANCE));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) DeleteProjection(io.crate.planner.projection.DeleteProjection) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 19 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryReduceOnCollectorGroupByWithCast.

@Test
public void testInsertFromSubQueryReduceOnCollectorGroupByWithCast() throws Exception {
    Merge merge = e.plan("insert into users (id, name) (select id, count(*) from users group by id)");
    Collect nonDistributedGroupBy = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) nonDistributedGroupBy.collectPhase());
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    EvalProjection collectTopN = (EvalProjection) collectPhase.projections().get(1);
    assertThat(collectTopN.outputs(), contains(isInputColumn(0), isFunction("to_string")));
    ColumnIndexWriterProjection columnIndexWriterProjection = (ColumnIndexWriterProjection) collectPhase.projections().get(2);
    assertThat(columnIndexWriterProjection.columnReferences(), contains(isReference("id"), isReference("name")));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(MergeCountProjection.class)));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 20 with RoutedCollectPhase

use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.

the class InsertPlannerTest method testInsertFromQueryWithPartitionedColumn.

@Test
public void testInsertFromQueryWithPartitionedColumn() throws Exception {
    Merge planNode = e.plan("insert into users (id, date) (select id, date from parted_pks)");
    Collect queryAndFetch = (Collect) planNode.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) queryAndFetch.collectPhase());
    List<Symbol> toCollect = collectPhase.toCollect();
    assertThat(toCollect.size(), is(2));
    assertThat(toCollect.get(0), isFunction("to_long"));
    assertThat(((Function) toCollect.get(0)).arguments().get(0), isReference("_doc['id']"));
    assertThat((Reference) toCollect.get(1), equalTo(new Reference(new ReferenceIdent(TableDefinitions.PARTED_PKS_IDENT, "date"), RowGranularity.PARTITION, DataTypes.TIMESTAMP)));
}
Also used : Function(io.crate.analyze.symbol.Function) Collect(io.crate.planner.node.dql.Collect) Symbol(io.crate.analyze.symbol.Symbol) Reference(io.crate.metadata.Reference) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)48 Test (org.junit.Test)36 CrateUnitTest (io.crate.test.integration.CrateUnitTest)25 Collect (io.crate.planner.node.dql.Collect)18 MergePhase (io.crate.planner.node.dql.MergePhase)15 Merge (io.crate.planner.Merge)14 Routing (io.crate.metadata.Routing)10 Symbol (io.crate.analyze.symbol.Symbol)8 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)8 DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)7 Bucket (io.crate.data.Bucket)6 Reference (io.crate.metadata.Reference)6 Row (io.crate.data.Row)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 OrderBy (io.crate.analyze.OrderBy)3 Function (io.crate.analyze.symbol.Function)3 CollectionBucket (io.crate.data.CollectionBucket)3