use of io.crate.planner.PlannerContext in project crate by crate.
the class AlterBlobTablePlan 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);
TableInfo tableInfo = analyzedAlterTable.tableInfo();
AlterTable<Object> alterTable = analyzedAlterTable.alterTable().map(eval);
TableParameter tableParameter = getTableParameter(alterTable, TableParameters.ALTER_BLOB_TABLE_PARAMETERS);
maybeRaiseBlockedException(tableInfo, tableParameter.settings());
BoundAlterTable stmt = new BoundAlterTable(tableInfo, null, tableParameter, true, false);
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 AlterUserPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
SecureHash newPassword = UserActions.generateSecureHash(alterUser.properties(), params, plannerContext.transactionContext(), plannerContext.nodeContext());
userManager.alterUser(alterUser.userName(), newPassword).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
use of io.crate.planner.PlannerContext in project crate by crate.
the class CreateUserPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
SecureHash newPassword = UserActions.generateSecureHash(createUser.properties(), params, plannerContext.transactionContext(), plannerContext.nodeContext());
userManager.createUser(createUser.userName(), newPassword).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
use of io.crate.planner.PlannerContext 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.PlannerContext in project crate by crate.
the class Session method singleExec.
@VisibleForTesting
CompletableFuture<?> singleExec(Portal portal, ResultReceiver<?> resultReceiver, int maxRows) {
var activeConsumer = portal.activeConsumer();
if (activeConsumer != null && activeConsumer.suspended()) {
activeConsumer.replaceResultReceiver(resultReceiver, maxRows);
activeConsumer.resume();
return resultReceiver.completionFuture();
}
var jobId = UUIDs.dirtyUUID();
var routingProvider = new RoutingProvider(Randomness.get().nextInt(), planner.getAwarenessAttributes());
var clusterState = executor.clusterService().state();
var txnCtx = new CoordinatorTxnCtx(sessionContext);
var nodeCtx = executor.nodeContext();
var params = new RowN(portal.params().toArray());
var plannerContext = new PlannerContext(clusterState, routingProvider, jobId, txnCtx, nodeCtx, maxRows, params);
var analyzedStmt = portal.analyzedStatement();
String rawStatement = portal.preparedStmt().rawStatement();
if (analyzedStmt == null) {
String errorMsg = "Statement must have been analyzed: " + rawStatement;
jobsLogs.logPreExecutionFailure(jobId, rawStatement, errorMsg, sessionContext.sessionUser());
throw new IllegalStateException(errorMsg);
}
Plan plan;
try {
plan = planner.plan(analyzedStmt, plannerContext);
} catch (Throwable t) {
jobsLogs.logPreExecutionFailure(jobId, rawStatement, SQLExceptions.messageOf(t), sessionContext.sessionUser());
throw t;
}
if (!analyzedStmt.isWriteOperation()) {
resultReceiver = new RetryOnFailureResultReceiver(executor.clusterService(), clusterState, indexName -> executor.clusterService().state().metadata().hasIndex(indexName), resultReceiver, jobId, (newJobId, resultRec) -> retryQuery(newJobId, analyzedStmt, routingProvider, new RowConsumerToResultReceiver(resultRec, maxRows, new JobsLogsUpdateListener(newJobId, jobsLogs)), params, txnCtx, nodeCtx));
}
jobsLogs.logExecutionStart(jobId, rawStatement, sessionContext.sessionUser(), StatementClassifier.classify(plan));
RowConsumerToResultReceiver consumer = new RowConsumerToResultReceiver(resultReceiver, maxRows, new JobsLogsUpdateListener(jobId, jobsLogs));
portal.setActiveConsumer(consumer);
plan.execute(executor, plannerContext, consumer, params, SubQueryResults.EMPTY);
return resultReceiver.completionFuture();
}
Aggregations