Search in sources :

Example 16 with PlannerContext

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

the class Session method retryQuery.

private void retryQuery(UUID jobId, AnalyzedStatement stmt, RoutingProvider routingProvider, RowConsumer consumer, Row params, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx) {
    PlannerContext plannerContext = new PlannerContext(planner.currentClusterState(), routingProvider, jobId, txnCtx, nodeCtx, 0, params);
    Plan plan = planner.plan(stmt, plannerContext);
    plan.execute(executor, plannerContext, consumer, params, SubQueryResults.EMPTY);
}
Also used : PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan)

Example 17 with PlannerContext

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

the class TransportSchemaUpdateActionTest method testTemplateMappingUpdateFailsIfTypeIsDifferent.

@Test
public void testTemplateMappingUpdateFailsIfTypeIsDifferent() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addPartitionedTable("create table t (p int) partitioned by (p)").build();
    ClusterState currentState = clusterService.state();
    PlannerContext plannerContext = e.getPlannerContext(currentState);
    BoundAddColumn addXLong = AlterTableAddColumnPlan.bind(e.analyze("alter table t add column x long"), plannerContext.transactionContext(), plannerContext.nodeContext(), Row.EMPTY, SubQueryResults.EMPTY, null);
    BoundAddColumn addXString = AlterTableAddColumnPlan.bind(e.analyze("alter table t add column x string"), plannerContext.transactionContext(), plannerContext.nodeContext(), Row.EMPTY, SubQueryResults.EMPTY, null);
    String templateName = templateName("doc", "t");
    IndexTemplateMetadata template = currentState.metadata().templates().get(templateName);
    ClusterState stateWithXLong = ClusterState.builder(currentState).metadata(Metadata.builder(currentState.metadata()).put(IndexTemplateMetadata.builder(templateName).patterns(template.patterns()).putMapping(Constants.DEFAULT_MAPPING_TYPE, Strings.toString(JsonXContent.contentBuilder().map(addXLong.mapping())))).build()).build();
    expectedException.expect(IllegalArgumentException.class);
    TransportSchemaUpdateAction.updateTemplate(NamedXContentRegistry.EMPTY, stateWithXLong, templateName, addXString.mapping());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) BoundAddColumn(io.crate.analyze.BoundAddColumn) PlannerContext(io.crate.planner.PlannerContext) SQLExecutor(io.crate.testing.SQLExecutor) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 18 with PlannerContext

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

the class SQLExecutor method planInternal.

private <T> T planInternal(AnalyzedStatement analyzedStatement, UUID jobId, int fetchSize, Row params) {
    RoutingProvider routingProvider = new RoutingProvider(random.nextInt(), emptyList());
    PlannerContext plannerContext = new PlannerContext(planner.currentClusterState(), routingProvider, jobId, coordinatorTxnCtx, nodeCtx, fetchSize, null);
    Plan plan = planner.plan(analyzedStatement, plannerContext);
    if (plan instanceof LogicalPlan) {
        return (T) ((LogicalPlan) plan).build(plannerContext, Set.of(), new ProjectionBuilder(nodeCtx), TopN.NO_LIMIT, 0, null, null, params, new SubQueryResults(emptyMap()) {

            @Override
            public Object getSafe(SelectSymbol key) {
                return Literal.of(key.valueType(), null);
            }
        });
    }
    return (T) plan;
}
Also used : SelectSymbol(io.crate.expression.symbol.SelectSymbol) RoutingProvider(io.crate.metadata.RoutingProvider) PlannerContext(io.crate.planner.PlannerContext) SubQueryResults(io.crate.planner.operators.SubQueryResults) LogicalPlan(io.crate.planner.operators.LogicalPlan) CreateBlobTablePlan(io.crate.planner.node.ddl.CreateBlobTablePlan) LogicalPlan(io.crate.planner.operators.LogicalPlan) Plan(io.crate.planner.Plan) CreateTablePlan(io.crate.planner.node.ddl.CreateTablePlan) ProjectionBuilder(io.crate.execution.dsl.projection.builder.ProjectionBuilder)

Example 19 with PlannerContext

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

the class DependencyCarrierDDLTest method testClusterUpdateSettingsTask.

@Test
public void testClusterUpdateSettingsTask() throws Exception {
    final String persistentSetting = "stats.enabled";
    final String transientSetting = "bulk.request_timeout";
    // Update persistent only
    List<Assignment<Symbol>> persistentSettings = List.of(new Assignment<>(Literal.of(persistentSetting), List.of(Literal.of(false))));
    UpdateSettingsPlan node = new UpdateSettingsPlan(persistentSettings, true);
    PlannerContext plannerContext = mock(PlannerContext.class);
    Bucket objects = executePlan(node, plannerContext);
    assertThat(objects, contains(isRow(1L)));
    assertEquals("false", client().admin().cluster().prepareState().execute().actionGet().getState().metadata().persistentSettings().get(persistentSetting));
    // Update transient only
    List<Assignment<Symbol>> transientSettings = List.of(new Assignment<>(Literal.of(transientSetting), List.of(Literal.of("123s"))));
    node = new UpdateSettingsPlan(transientSettings, false);
    objects = executePlan(node, plannerContext);
    assertThat(objects, contains(isRow(1L)));
    assertEquals("123s", client().admin().cluster().prepareState().execute().actionGet().getState().metadata().transientSettings().get(transientSetting));
}
Also used : Assignment(io.crate.sql.tree.Assignment) PlannerContext(io.crate.planner.PlannerContext) Bucket(io.crate.data.Bucket) UpdateSettingsPlan(io.crate.planner.node.ddl.UpdateSettingsPlan) Test(org.junit.Test)

Example 20 with PlannerContext

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

the class BatchPortalTest method testEachStatementReceivesCorrectParams.

@Test
public void testEachStatementReceivesCorrectParams() throws Throwable {
    SQLExecutor sqlExecutor = SQLExecutor.builder(clusterService).addTable("create table t1 (x int)").build();
    Plan insertPlan = new Plan() {

        @Override
        public StatementType type() {
            return StatementType.INSERT;
        }

        @Override
        public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
            consumer.accept(InMemoryBatchIterator.of(params, null), null);
        }
    };
    Planner planner = new Planner(Settings.EMPTY, clusterService, sqlExecutor.nodeCtx, new TableStats(), null, null, sqlExecutor.schemas(), new StubUserManager(), mock(SessionSettingRegistry.class)) {

        @Override
        public Plan plan(AnalyzedStatement analyzedStatement, PlannerContext plannerContext) {
            return insertPlan;
        }
    };
    DependencyCarrier executor = mock(DependencyCarrier.class, Answers.RETURNS_MOCKS);
    Session session = new Session(sqlExecutor.nodeCtx, sqlExecutor.analyzer, planner, new JobsLogs(() -> false), false, executor, AccessControl.DISABLED, SessionContext.systemSessionContext());
    session.parse("S_1", "insert into t1(x) values(1)", Collections.emptyList());
    session.bind("Portal", "S_1", Collections.emptyList(), null);
    final ArrayList<Object[]> s1Rows = new ArrayList<>();
    session.execute("Portal", 0, new BaseResultReceiver() {

        @Override
        public void setNextRow(Row row) {
            s1Rows.add(row.materialize());
        }
    });
    session.parse("S_2", "insert into t1(x) values(?)", Collections.emptyList());
    session.bind("Portal", "S_2", Collections.singletonList(2), null);
    final ArrayList<Object[]> s2Rows = new ArrayList<>();
    session.execute("Portal", 0, new BaseResultReceiver() {

        @Override
        public void setNextRow(Row row) {
            s2Rows.add(row.materialize());
        }
    });
    session.sync().get(5, TimeUnit.SECONDS);
    assertThat(s1Rows, contains(emptyArray()));
    assertThat(s2Rows, contains(arrayContaining(is(2))));
}
Also used : DependencyCarrier(io.crate.planner.DependencyCarrier) SubQueryResults(io.crate.planner.operators.SubQueryResults) ArrayList(java.util.ArrayList) Plan(io.crate.planner.Plan) TableStats(io.crate.statistics.TableStats) StubUserManager(io.crate.user.StubUserManager) SessionSettingRegistry(io.crate.metadata.settings.session.SessionSettingRegistry) PlannerContext(io.crate.planner.PlannerContext) SQLExecutor(io.crate.testing.SQLExecutor) BaseResultReceiver(io.crate.action.sql.BaseResultReceiver) Planner(io.crate.planner.Planner) AnalyzedStatement(io.crate.analyze.AnalyzedStatement) RowConsumer(io.crate.data.RowConsumer) Row(io.crate.data.Row) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) Session(io.crate.action.sql.Session) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

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