Search in sources :

Example 26 with RowConsumer

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);
}
Also used : CreateUserDefinedFunctionRequest(io.crate.expression.udf.CreateUserDefinedFunctionRequest) StringType(io.crate.types.StringType) AnalyzedCreateFunction(io.crate.analyze.AnalyzedCreateFunction) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Function(java.util.function.Function) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) UserDefinedFunctionMetadata(io.crate.expression.udf.UserDefinedFunctionMetadata) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) Row1(io.crate.data.Row1) OneRowActionListener(io.crate.execution.support.OneRowActionListener) UserDefinedFunctionMetadata(io.crate.expression.udf.UserDefinedFunctionMetadata) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) CreateUserDefinedFunctionRequest(io.crate.expression.udf.CreateUserDefinedFunctionRequest)

Example 27 with RowConsumer

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);
        }
    }));
}
Also used : Arrays(java.util.Arrays) Operation(io.crate.metadata.table.Operation) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) Function(java.util.function.Function) PartitionName(io.crate.metadata.PartitionName) DependencyCarrier(io.crate.planner.DependencyCarrier) HashSet(java.util.HashSet) WAIT_FOR_COMPLETION(io.crate.analyze.SnapshotSettings.WAIT_FOR_COMPLETION) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) AnalyzedCreateSnapshot(io.crate.analyze.AnalyzedCreateSnapshot) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) GenericPropertiesConverter(io.crate.analyze.GenericPropertiesConverter) SnapshotState(org.elasticsearch.snapshots.SnapshotState) OneRowActionListener(io.crate.execution.support.OneRowActionListener) PartitionUnknownException(io.crate.exceptions.PartitionUnknownException) PartitionPropertiesAnalyzer.toPartitionName(io.crate.analyze.PartitionPropertiesAnalyzer.toPartitionName) SchemaInfo(io.crate.metadata.table.SchemaInfo) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) NodeContext(io.crate.metadata.NodeContext) CreateSnapshotException(io.crate.exceptions.CreateSnapshotException) Table(io.crate.sql.tree.Table) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) Lists2(io.crate.common.collections.Lists2) SnapshotSettings(io.crate.analyze.SnapshotSettings) RowConsumer(io.crate.data.RowConsumer) Logger(org.apache.logging.log4j.Logger) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) IGNORE_UNAVAILABLE(io.crate.analyze.SnapshotSettings.IGNORE_UNAVAILABLE) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) CreateSnapshotException(io.crate.exceptions.CreateSnapshotException) CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)

Example 28 with RowConsumer

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)));
}
Also used : NodeContext(io.crate.metadata.NodeContext) GenericPropertiesConverter.genericPropertiesToSettings(io.crate.analyze.GenericPropertiesConverter.genericPropertiesToSettings) RepositoryParamValidator(io.crate.analyze.repositories.RepositoryParamValidator) Function(java.util.function.Function) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Row(io.crate.data.Row) AnalyzedCreateRepository(io.crate.analyze.AnalyzedCreateRepository) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest)

Example 29 with RowConsumer

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));
}
Also used : RowConsumer(io.crate.data.RowConsumer) Row(io.crate.data.Row) RelationsUnknown(io.crate.exceptions.RelationsUnknown) SubQueryResults(io.crate.planner.operators.SubQueryResults) DropViewRequest(io.crate.execution.ddl.views.DropViewRequest) DropViewResponse(io.crate.execution.ddl.views.DropViewResponse) AnalyzedDropView(io.crate.analyze.AnalyzedDropView) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Function(java.util.function.Function) Row1(io.crate.data.Row1) DropViewRequest(io.crate.execution.ddl.views.DropViewRequest) Row1(io.crate.data.Row1) DropViewResponse(io.crate.execution.ddl.views.DropViewResponse) RelationsUnknown(io.crate.exceptions.RelationsUnknown) Row(io.crate.data.Row)

Example 30 with RowConsumer

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)));
}
Also used : AlterTable(io.crate.sql.tree.AlterTable) AnalyzedAlterTable(io.crate.analyze.AnalyzedAlterTable) BoundAlterTable(io.crate.analyze.BoundAlterTable) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) PartitionPropertiesAnalyzer(io.crate.analyze.PartitionPropertiesAnalyzer) Operation(io.crate.metadata.table.Operation) Function(java.util.function.Function) PartitionName(io.crate.metadata.PartitionName) DependencyCarrier(io.crate.planner.DependencyCarrier) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Nullable(javax.annotation.Nullable) TableParameter(io.crate.analyze.TableParameter) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) NodeContext(io.crate.metadata.NodeContext) TablePropertiesAnalyzer(io.crate.analyze.TablePropertiesAnalyzer) Table(io.crate.sql.tree.Table) TableParameters(io.crate.analyze.TableParameters) RowConsumer(io.crate.data.RowConsumer) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) BoundAlterTable(io.crate.analyze.BoundAlterTable)

Aggregations

RowConsumer (io.crate.data.RowConsumer)37 Row (io.crate.data.Row)26 Row1 (io.crate.data.Row1)24 SubQueryResults (io.crate.planner.operators.SubQueryResults)24 OneRowActionListener (io.crate.execution.support.OneRowActionListener)22 DependencyCarrier (io.crate.planner.DependencyCarrier)22 PlannerContext (io.crate.planner.PlannerContext)22 Plan (io.crate.planner.Plan)21 Symbol (io.crate.expression.symbol.Symbol)18 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)17 Function (java.util.function.Function)17 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)12 NodeContext (io.crate.metadata.NodeContext)11 List (java.util.List)10 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)9 ArrayList (java.util.ArrayList)9 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)8 Test (org.junit.Test)8 DocTableInfo (io.crate.metadata.doc.DocTableInfo)7 Settings (org.elasticsearch.common.settings.Settings)7