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