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);
}
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());
}
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;
}
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));
}
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))));
}
Aggregations