use of io.crate.planner.DependencyCarrier in project crate by crate.
the class ResetSettingsPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), x, params, subQueryResults);
Settings settings = buildSettingsFrom(resetAnalyzedStatement.settingsToRemove(), eval);
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest().persistentSettings(settings).transientSettings(settings);
OneRowActionListener<ClusterUpdateSettingsResponse> actionListener = new OneRowActionListener<>(consumer, r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L));
dependencies.transportActionProvider().transportClusterUpdateSettingsAction().execute(request, actionListener);
}
use of io.crate.planner.DependencyCarrier 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))));
}
use of io.crate.planner.DependencyCarrier in project crate by crate.
the class RestoreSnapshotPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row parameters, SubQueryResults subQueryResults) {
BoundRestoreSnapshot stmt = bind(restoreSnapshot, plannerContext.transactionContext(), dependencies.nodeContext(), parameters, subQueryResults, dependencies.schemas());
var settings = stmt.settings();
boolean ignoreUnavailable = IGNORE_UNAVAILABLE.get(settings);
var transportActionProvider = dependencies.transportActionProvider();
resolveIndexNames(restoreSnapshot.repository(), stmt.restoreTables(), ignoreUnavailable, transportActionProvider.transportGetSnapshotsAction()).whenComplete((ResolveIndicesAndTemplatesContext ctx, Throwable t) -> {
if (t == null) {
String[] indexNames = ctx.resolvedIndices().toArray(new String[0]);
String[] templateNames = stmt.includeTables() && stmt.restoreTables().isEmpty() ? new String[] { ALL_TEMPLATES } : ctx.resolvedTemplates().toArray(new String[0]);
// ignore_unavailable as set by statement
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
RestoreSnapshotRequest request = new RestoreSnapshotRequest(restoreSnapshot.repository(), restoreSnapshot.snapshot()).indices(indexNames).templates(templateNames).indicesOptions(indicesOptions).settings(settings).waitForCompletion(WAIT_FOR_COMPLETION.get(settings)).includeIndices(stmt.includeTables()).includeAliases(stmt.includeTables()).includeCustomMetadata(stmt.includeCustomMetadata()).customMetadataTypes(stmt.customMetadataTypes()).includeGlobalSettings(stmt.includeGlobalSettings()).globalSettings(stmt.globalSettings());
transportActionProvider.transportRestoreSnapshotAction().execute(request, new OneRowActionListener<>(consumer, r -> new Row1(r == null ? -1L : 1L)));
}
});
}
use of io.crate.planner.DependencyCarrier in project crate by crate.
the class CreateAnalyzerPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
ClusterUpdateSettingsRequest request = createRequest(createAnalyzer, plannerContext.transactionContext(), dependencies.nodeContext(), params, subQueryResults, dependencies.fulltextAnalyzerResolver());
dependencies.transportActionProvider().transportClusterUpdateSettingsAction().execute(request, new OneRowActionListener<>(consumer, r -> new Row1(1L)));
}
use of io.crate.planner.DependencyCarrier in project crate by crate.
the class CreateFunctionPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), x, params, subQueryResults);
UserDefinedFunctionMetadata metadata = new UserDefinedFunctionMetadata(createFunction.schema(), createFunction.name(), createFunction.arguments(), createFunction.returnType(), StringType.INSTANCE.sanitizeValue(eval.apply(createFunction.language())), StringType.INSTANCE.sanitizeValue(eval.apply(createFunction.definition())));
CreateUserDefinedFunctionRequest request = new CreateUserDefinedFunctionRequest(metadata, createFunction.replace());
OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(consumer, r -> new Row1(1L));
dependencies.createFunctionAction().execute(request, listener);
}
Aggregations