Search in sources :

Example 16 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener 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 17 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener 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 18 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener 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 19 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener 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)

Example 20 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener 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));
    }
}
Also used : DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) List(java.util.List) Row(io.crate.data.Row) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) OneRowActionListener(io.crate.execution.support.OneRowActionListener) SentinelRow(io.crate.data.SentinelRow) Row1(io.crate.data.Row1) Row1(io.crate.data.Row1) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)

Aggregations

Row1 (io.crate.data.Row1)26 OneRowActionListener (io.crate.execution.support.OneRowActionListener)26 Row (io.crate.data.Row)22 RowConsumer (io.crate.data.RowConsumer)22 SubQueryResults (io.crate.planner.operators.SubQueryResults)22 DependencyCarrier (io.crate.planner.DependencyCarrier)19 Plan (io.crate.planner.Plan)19 PlannerContext (io.crate.planner.PlannerContext)19 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)15 Symbol (io.crate.expression.symbol.Symbol)15 Function (java.util.function.Function)15 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)11 NodeContext (io.crate.metadata.NodeContext)10 Settings (org.elasticsearch.common.settings.Settings)10 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)9 List (java.util.List)7 RelationName (io.crate.metadata.RelationName)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 Table (io.crate.sql.tree.Table)6 ArrayList (java.util.ArrayList)5