Search in sources :

Example 6 with SelectSymbol

use of io.crate.expression.symbol.SelectSymbol 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 7 with SelectSymbol

use of io.crate.expression.symbol.SelectSymbol in project crate by crate.

the class UpdatePlannerTest method testMultiValueSubQueryWithinSingleValueSubQueryDoesNotInheritSoftLimit.

@Test
public void testMultiValueSubQueryWithinSingleValueSubQueryDoesNotInheritSoftLimit() {
    MultiPhasePlan plan = e.plan("update users set ints = (" + "   select count(id) from users where id in (select unnest([1, 2, 3, 4])))");
    assertThat(plan.rootPlan, instanceOf(UpdatePlanner.Update.class));
    Map<LogicalPlan, SelectSymbol> rootPlanDependencies = plan.dependencies;
    LogicalPlan outerSubSelectPlan = rootPlanDependencies.keySet().iterator().next();
    SelectSymbol outerSubSelectSymbol = rootPlanDependencies.values().iterator().next();
    assertThat(outerSubSelectSymbol.getResultType(), is(SINGLE_COLUMN_SINGLE_VALUE));
    assertThat(outerSubSelectPlan.numExpectedRows(), is(2L));
    LogicalPlan innerSubSelectPlan = outerSubSelectPlan.dependencies().keySet().iterator().next();
    SelectSymbol innerSubSelectSymbol = outerSubSelectPlan.dependencies().values().iterator().next();
    assertThat(innerSubSelectSymbol.getResultType(), is(SINGLE_COLUMN_MULTIPLE_VALUES));
    assertThat(innerSubSelectPlan.numExpectedRows(), is(-1L));
}
Also used : SelectSymbol(io.crate.expression.symbol.SelectSymbol) LogicalPlan(io.crate.planner.operators.LogicalPlan) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

SelectSymbol (io.crate.expression.symbol.SelectSymbol)7 LogicalPlan (io.crate.planner.operators.LogicalPlan)4 SubQueryResults (io.crate.planner.operators.SubQueryResults)4 PlannerContext (io.crate.planner.PlannerContext)3 WhereClause (io.crate.analyze.WhereClause)2 Row (io.crate.data.Row)2 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)2 ProjectionBuilder (io.crate.execution.dsl.projection.builder.ProjectionBuilder)2 Symbol (io.crate.expression.symbol.Symbol)2 RoutingProvider (io.crate.metadata.RoutingProvider)2 DependencyCarrier (io.crate.planner.DependencyCarrier)2 Plan (io.crate.planner.Plan)2 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)1 SessionContext (io.crate.action.sql.SessionContext)1 AnalyzedUpdateStatement (io.crate.analyze.AnalyzedUpdateStatement)1 OrderBy (io.crate.analyze.OrderBy)1 QueriedSelectRelation (io.crate.analyze.QueriedSelectRelation)1 AbstractTableRelation (io.crate.analyze.relations.AbstractTableRelation)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1