use of io.crate.data.RowConsumer 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);
}
use of io.crate.data.RowConsumer 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.data.RowConsumer 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.data.RowConsumer in project crate by crate.
the class DropViewPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
DropViewRequest request = new DropViewRequest(dropView.views(), dropView.ifExists());
Function<DropViewResponse, Row> responseToRow = resp -> {
if (dropView.ifExists() || resp.missing().isEmpty()) {
return new Row1((long) dropView.views().size() - resp.missing().size());
}
throw new RelationsUnknown(resp.missing());
};
dependencies.dropViewAction().execute(request, new OneRowActionListener<>(consumer, responseToRow));
}
use of io.crate.data.RowConsumer 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)));
}
Aggregations