Search in sources :

Example 31 with PlannerContext

use of io.crate.planner.PlannerContext in project crate by crate.

the class CreateSnapshotPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row parameters, SubQueryResults subQueryResults) {
    CreateSnapshotRequest request = createRequest(createSnapshot, plannerContext.transactionContext(), dependencies.nodeContext(), parameters, subQueryResults, dependencies.schemas());
    var transportCreateSnapshotAction = dependencies.transportActionProvider().transportCreateSnapshotAction();
    transportCreateSnapshotAction.execute(request, new OneRowActionListener<>(consumer, response -> {
        SnapshotInfo snapshotInfo = response.getSnapshotInfo();
        if (// if wait_for_completion is false, the snapshotInfo is null
        snapshotInfo != null && snapshotInfo.state() == SnapshotState.FAILED) {
            // fail request if snapshot creation failed
            String reason = response.getSnapshotInfo().reason().replaceAll("Index", "Table").replaceAll("Indices", "Tables");
            consumer.accept(null, new CreateSnapshotException(createSnapshot.snapshot(), reason));
            return new Row1(-1L);
        } else {
            return new Row1(1L);
        }
    }));
}
Also used : Arrays(java.util.Arrays) Operation(io.crate.metadata.table.Operation) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) Function(java.util.function.Function) PartitionName(io.crate.metadata.PartitionName) DependencyCarrier(io.crate.planner.DependencyCarrier) HashSet(java.util.HashSet) WAIT_FOR_COMPLETION(io.crate.analyze.SnapshotSettings.WAIT_FOR_COMPLETION) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) AnalyzedCreateSnapshot(io.crate.analyze.AnalyzedCreateSnapshot) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) GenericPropertiesConverter(io.crate.analyze.GenericPropertiesConverter) SnapshotState(org.elasticsearch.snapshots.SnapshotState) OneRowActionListener(io.crate.execution.support.OneRowActionListener) PartitionUnknownException(io.crate.exceptions.PartitionUnknownException) PartitionPropertiesAnalyzer.toPartitionName(io.crate.analyze.PartitionPropertiesAnalyzer.toPartitionName) SchemaInfo(io.crate.metadata.table.SchemaInfo) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) NodeContext(io.crate.metadata.NodeContext) CreateSnapshotException(io.crate.exceptions.CreateSnapshotException) Table(io.crate.sql.tree.Table) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) Lists2(io.crate.common.collections.Lists2) SnapshotSettings(io.crate.analyze.SnapshotSettings) RowConsumer(io.crate.data.RowConsumer) Logger(org.apache.logging.log4j.Logger) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) IGNORE_UNAVAILABLE(io.crate.analyze.SnapshotSettings.IGNORE_UNAVAILABLE) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) CreateSnapshotException(io.crate.exceptions.CreateSnapshotException) CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)

Example 32 with PlannerContext

use of io.crate.planner.PlannerContext in project crate by crate.

the class CreateRepositoryPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row parameters, SubQueryResults subQueryResults) {
    PutRepositoryRequest request = createRequest(createRepository, plannerContext.transactionContext(), dependencies.nodeContext(), parameters, subQueryResults, dependencies.repositoryParamValidator());
    dependencies.repositoryService().execute(request).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
Also used : NodeContext(io.crate.metadata.NodeContext) GenericPropertiesConverter.genericPropertiesToSettings(io.crate.analyze.GenericPropertiesConverter.genericPropertiesToSettings) RepositoryParamValidator(io.crate.analyze.repositories.RepositoryParamValidator) Function(java.util.function.Function) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Row(io.crate.data.Row) AnalyzedCreateRepository(io.crate.analyze.AnalyzedCreateRepository) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest)

Example 33 with PlannerContext

use of io.crate.planner.PlannerContext in project crate by crate.

the class UpdatePlanner method plan.

public static Plan plan(AnalyzedUpdateStatement update, PlannerContext plannerCtx, SubqueryPlanner subqueryPlanner) {
    if (update.outputs() != null && !plannerCtx.clusterState().getNodes().getMinNodeVersion().onOrAfter(Version.V_4_2_0)) {
        throw new UnsupportedFeatureException(RETURNING_VERSION_ERROR_MSG);
    }
    AbstractTableRelation<?> table = update.table();
    Plan plan;
    if (table instanceof DocTableRelation) {
        DocTableRelation docTable = (DocTableRelation) table;
        plan = plan(docTable, update.assignmentByTargetCol(), update.query(), plannerCtx, update.outputs());
    } else {
        plan = new Update((plannerContext, params, subQueryValues) -> sysUpdate(plannerContext, (TableRelation) table, update.assignmentByTargetCol(), update.query(), params, subQueryValues, update.outputs()));
    }
    Map<LogicalPlan, SelectSymbol> subQueries = subqueryPlanner.planSubQueries(update);
    return MultiPhasePlan.createIfNeeded(plan, subQueries);
}
Also used : UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) UpdateProjection(io.crate.execution.dsl.projection.UpdateProjection) SessionContext(io.crate.action.sql.SessionContext) SysUpdateProjection(io.crate.execution.dsl.projection.SysUpdateProjection) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Collections.singletonList(java.util.Collections.singletonList) DependencyCarrier(io.crate.planner.DependencyCarrier) Map(java.util.Map) SelectSymbol(io.crate.expression.symbol.SelectSymbol) DistributionInfo(io.crate.planner.distribution.DistributionInfo) DocSysColumns(io.crate.metadata.doc.DocSysColumns) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) LogicalPlan(io.crate.planner.operators.LogicalPlan) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) ExecutionPlan(io.crate.planner.ExecutionPlan) List(java.util.List) Version(org.elasticsearch.Version) Row(io.crate.data.Row) Projection(io.crate.execution.dsl.projection.Projection) Symbol(io.crate.expression.symbol.Symbol) DataTypes(io.crate.types.DataTypes) SubQueryResults(io.crate.planner.operators.SubQueryResults) Assignments(io.crate.expression.symbol.Assignments) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) InputColumn(io.crate.expression.symbol.InputColumn) SubqueryPlanner(io.crate.planner.SubqueryPlanner) WhereClauseOptimizer(io.crate.planner.WhereClauseOptimizer) CompletableFuture(java.util.concurrent.CompletableFuture) AnalyzedUpdateStatement(io.crate.analyze.AnalyzedUpdateStatement) ArrayList(java.util.ArrayList) Routing(io.crate.metadata.Routing) Objects.requireNonNull(java.util.Objects.requireNonNull) UpdateById(io.crate.planner.node.dml.UpdateById) VersioningValidationException(io.crate.exceptions.VersioningValidationException) TopN(io.crate.execution.engine.pipeline.TopN) Optimizer(io.crate.planner.optimizer.symbol.Optimizer) Nullable(javax.annotation.Nullable) MergeCountProjection(io.crate.execution.dsl.projection.MergeCountProjection) TableRelation(io.crate.analyze.relations.TableRelation) WhereClause(io.crate.analyze.WhereClause) NodeOperationTree(io.crate.execution.dsl.phases.NodeOperationTree) Reference(io.crate.metadata.Reference) NodeOperationTreeGenerator(io.crate.execution.engine.NodeOperationTreeGenerator) SubQueryAndParamBinder(io.crate.planner.operators.SubQueryAndParamBinder) Merge(io.crate.planner.Merge) RoutingProvider(io.crate.metadata.RoutingProvider) RowConsumer(io.crate.data.RowConsumer) DocTableRelation(io.crate.analyze.relations.DocTableRelation) AbstractTableRelation(io.crate.analyze.relations.AbstractTableRelation) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) MultiPhasePlan(io.crate.planner.MultiPhasePlan) Collect(io.crate.planner.node.dql.Collect) SelectSymbol(io.crate.expression.symbol.SelectSymbol) UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) DocTableRelation(io.crate.analyze.relations.DocTableRelation) LogicalPlan(io.crate.planner.operators.LogicalPlan) LogicalPlan(io.crate.planner.operators.LogicalPlan) ExecutionPlan(io.crate.planner.ExecutionPlan) Plan(io.crate.planner.Plan) MultiPhasePlan(io.crate.planner.MultiPhasePlan)

Example 34 with PlannerContext

use of io.crate.planner.PlannerContext in project crate by crate.

the class AlterTablePlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
    BoundAlterTable stmt = bind(alterTable, plannerContext.transactionContext(), dependencies.nodeContext(), params, subQueryResults);
    dependencies.alterTableOperation().executeAlterTable(stmt).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
Also used : AlterTable(io.crate.sql.tree.AlterTable) AnalyzedAlterTable(io.crate.analyze.AnalyzedAlterTable) BoundAlterTable(io.crate.analyze.BoundAlterTable) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) PartitionPropertiesAnalyzer(io.crate.analyze.PartitionPropertiesAnalyzer) Operation(io.crate.metadata.table.Operation) Function(java.util.function.Function) PartitionName(io.crate.metadata.PartitionName) DependencyCarrier(io.crate.planner.DependencyCarrier) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Nullable(javax.annotation.Nullable) TableParameter(io.crate.analyze.TableParameter) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) NodeContext(io.crate.metadata.NodeContext) TablePropertiesAnalyzer(io.crate.analyze.TablePropertiesAnalyzer) Table(io.crate.sql.tree.Table) TableParameters(io.crate.analyze.TableParameters) RowConsumer(io.crate.data.RowConsumer) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) BoundAlterTable(io.crate.analyze.BoundAlterTable)

Example 35 with PlannerContext

use of io.crate.planner.PlannerContext in project crate by crate.

the class DeleteAllPartitions method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    if (partitions.isEmpty()) {
        consumer.accept(InMemoryBatchIterator.of(new Row1(0L), SentinelRow.SENTINEL), null);
    } else {
        /*
             * table is partitioned, in case of concurrent "delete from partitions"
             * it could be that some partitions are already deleted,
             * so ignore it if some are missing
             */
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(partitions().toArray(new String[0])).indicesOptions(IndicesOptions.lenientExpandOpen());
        executor.transportActionProvider().transportDeleteIndexAction().execute(deleteIndexRequest, new OneRowActionListener<>(consumer, r -> Row1.ROW_COUNT_UNKNOWN));
    }
}
Also used : DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) List(java.util.List) Row(io.crate.data.Row) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) OneRowActionListener(io.crate.execution.support.OneRowActionListener) SentinelRow(io.crate.data.SentinelRow) Row1(io.crate.data.Row1) Row1(io.crate.data.Row1) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)

Aggregations

PlannerContext (io.crate.planner.PlannerContext)40 Row (io.crate.data.Row)31 DependencyCarrier (io.crate.planner.DependencyCarrier)30 RowConsumer (io.crate.data.RowConsumer)29 Plan (io.crate.planner.Plan)28 SubQueryResults (io.crate.planner.operators.SubQueryResults)27 Row1 (io.crate.data.Row1)26 Symbol (io.crate.expression.symbol.Symbol)24 Function (java.util.function.Function)22 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)19 OneRowActionListener (io.crate.execution.support.OneRowActionListener)19 List (java.util.List)17 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)15 ArrayList (java.util.ArrayList)15 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)13 Map (java.util.Map)13 NodeContext (io.crate.metadata.NodeContext)12 DocTableInfo (io.crate.metadata.doc.DocTableInfo)12 Nullable (javax.annotation.Nullable)12 AbstractTableRelation (io.crate.analyze.relations.AbstractTableRelation)10