Search in sources :

Example 1 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener in project crate by crate.

the class RefreshTablePlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row parameters, SubQueryResults subQueryResults) {
    if (analysis.tables().isEmpty()) {
        consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
        return;
    }
    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), x, parameters, subQueryResults);
    ArrayList<String> toRefresh = new ArrayList<>();
    for (Map.Entry<Table<Symbol>, DocTableInfo> table : analysis.tables().entrySet()) {
        var tableInfo = table.getValue();
        var tableSymbol = table.getKey();
        if (tableSymbol.partitionProperties().isEmpty()) {
            toRefresh.addAll(Arrays.asList(tableInfo.concreteOpenIndices()));
        } else {
            var partitionName = toPartitionName(tableInfo, Lists2.map(tableSymbol.partitionProperties(), p -> p.map(eval)));
            if (!tableInfo.partitions().contains(partitionName)) {
                throw new PartitionUnknownException(partitionName);
            }
            toRefresh.add(partitionName.asIndexName());
        }
    }
    RefreshRequest request = new RefreshRequest(toRefresh.toArray(String[]::new));
    request.indicesOptions(IndicesOptions.lenientExpandOpen());
    var transportRefreshAction = dependencies.transportActionProvider().transportRefreshAction();
    transportRefreshAction.execute(request, new OneRowActionListener<>(consumer, response -> new Row1(toRefresh.isEmpty() ? -1L : (long) toRefresh.size())));
}
Also used : AnalyzedRefreshTable(io.crate.analyze.AnalyzedRefreshTable) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Arrays(java.util.Arrays) SENTINEL(io.crate.data.SentinelRow.SENTINEL) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) Table(io.crate.sql.tree.Table) Function(java.util.function.Function) Lists2(io.crate.common.collections.Lists2) ArrayList(java.util.ArrayList) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) 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) Map(java.util.Map) SubQueryResults(io.crate.planner.operators.SubQueryResults) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) OneRowActionListener(io.crate.execution.support.OneRowActionListener) PartitionUnknownException(io.crate.exceptions.PartitionUnknownException) PartitionPropertiesAnalyzer.toPartitionName(io.crate.analyze.PartitionPropertiesAnalyzer.toPartitionName) Row1(io.crate.data.Row1) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) DocTableInfo(io.crate.metadata.doc.DocTableInfo) PartitionUnknownException(io.crate.exceptions.PartitionUnknownException) AnalyzedRefreshTable(io.crate.analyze.AnalyzedRefreshTable) Table(io.crate.sql.tree.Table) ArrayList(java.util.ArrayList) Row1(io.crate.data.Row1) Map(java.util.Map)

Example 2 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener in project crate by crate.

the class CreateViewPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    User owner = createViewStmt.owner();
    String formattedQuery = SqlFormatter.formatSql(createViewStmt.query(), makeExpressions(params));
    ensureFormattedQueryCanStillBeAnalyzed(createViewStmt.name(), dependencies.nodeContext(), dependencies.schemas(), plannerContext.transactionContext(), formattedQuery, createViewStmt.replaceExisting());
    CreateViewRequest request = new CreateViewRequest(createViewStmt.name(), formattedQuery, createViewStmt.replaceExisting(), owner == null ? null : owner.name());
    dependencies.createViewAction().execute(request, new OneRowActionListener<>(consumer, resp -> {
        if (resp.alreadyExistsFailure()) {
            throw new RelationAlreadyExists(createViewStmt.name());
        }
        return new Row1(1L);
    }));
}
Also used : ParamTypeHints(io.crate.analyze.ParamTypeHints) Literal(io.crate.sql.tree.Literal) RelationName(io.crate.metadata.RelationName) SearchPath(io.crate.metadata.SearchPath) DefaultTraversalVisitor(io.crate.sql.tree.DefaultTraversalVisitor) ArrayList(java.util.ArrayList) CreateViewStmt(io.crate.analyze.CreateViewStmt) SqlParser(io.crate.sql.parser.SqlParser) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Query(io.crate.sql.tree.Query) Nullable(javax.annotation.Nullable) NodeContext(io.crate.metadata.NodeContext) ParameterExpression(io.crate.sql.tree.ParameterExpression) User(io.crate.user.User) CreateViewRequest(io.crate.execution.ddl.views.CreateViewRequest) SqlFormatter(io.crate.sql.SqlFormatter) Table(io.crate.sql.tree.Table) RowConsumer(io.crate.data.RowConsumer) List(java.util.List) Row(io.crate.data.Row) RelationAlreadyExists(io.crate.exceptions.RelationAlreadyExists) Symbol(io.crate.expression.symbol.Symbol) RelationAnalyzer(io.crate.analyze.relations.RelationAnalyzer) SubQueryResults(io.crate.planner.operators.SubQueryResults) Schemas(io.crate.metadata.Schemas) Expression(io.crate.sql.tree.Expression) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) User(io.crate.user.User) RelationAlreadyExists(io.crate.exceptions.RelationAlreadyExists) CreateViewRequest(io.crate.execution.ddl.views.CreateViewRequest)

Example 3 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener in project crate by crate.

the class CreateTablePlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    BoundCreateTable boundCreateTable = bind(createTable, plannerContext.transactionContext(), dependencies.nodeContext(), params, subQueryResults, numberOfShards, schemas, dependencies.fulltextAnalyzerResolver());
    if (boundCreateTable.noOp()) {
        consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
        return;
    }
    tableCreator.create(boundCreateTable).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
Also used : AnalyzedColumnDefinition(io.crate.analyze.AnalyzedColumnDefinition) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) SENTINEL(io.crate.data.SentinelRow.SENTINEL) GenericProperties(io.crate.sql.tree.GenericProperties) Function(java.util.function.Function) DependencyCarrier(io.crate.planner.DependencyCarrier) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) OneRowActionListener(io.crate.execution.support.OneRowActionListener) BoundCreateTable(io.crate.analyze.BoundCreateTable) FulltextAnalyzerResolver(io.crate.metadata.FulltextAnalyzerResolver) Nullable(javax.annotation.Nullable) TableParameter(io.crate.analyze.TableParameter) CreateTable(io.crate.sql.tree.CreateTable) AnalyzedCreateTable(io.crate.analyze.AnalyzedCreateTable) NodeContext(io.crate.metadata.NodeContext) PartitionedBy(io.crate.sql.tree.PartitionedBy) TableCreator(io.crate.execution.ddl.tables.TableCreator) TablePropertiesAnalyzer(io.crate.analyze.TablePropertiesAnalyzer) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) ColumnIdent(io.crate.metadata.ColumnIdent) SubQueryAndParamBinder(io.crate.planner.operators.SubQueryAndParamBinder) TableParameters(io.crate.analyze.TableParameters) RowConsumer(io.crate.data.RowConsumer) AnalyzedTableElements(io.crate.analyze.AnalyzedTableElements) NumberOfShards(io.crate.analyze.NumberOfShards) ClusteredBy(io.crate.sql.tree.ClusteredBy) 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) Optional(java.util.Optional) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) BoundCreateTable(io.crate.analyze.BoundCreateTable)

Example 4 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener in project crate by crate.

the class AlterTableOpenClosePlan 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);
    DocTableInfo tableInfo = analyzedAlterTable.tableInfo();
    Table<Object> table = analyzedAlterTable.table().map(eval);
    PartitionName partitionName = null;
    if (tableInfo.isPartitioned()) {
        partitionName = PartitionPropertiesAnalyzer.createPartitionName(table.partitionProperties(), tableInfo);
    }
    dependencies.alterTableOperation().executeAlterTableOpenClose(tableInfo, analyzedAlterTable.isOpenTable(), partitionName).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) Table(io.crate.sql.tree.Table) PartitionPropertiesAnalyzer(io.crate.analyze.PartitionPropertiesAnalyzer) Function(java.util.function.Function) PartitionName(io.crate.metadata.PartitionName) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) 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) AnalyzedAlterTableOpenClose(io.crate.analyze.AnalyzedAlterTableOpenClose) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) PartitionName(io.crate.metadata.PartitionName) Row1(io.crate.data.Row1) DocTableInfo(io.crate.metadata.doc.DocTableInfo)

Example 5 with OneRowActionListener

use of io.crate.execution.support.OneRowActionListener in project crate by crate.

the class SwapTablePlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    boolean dropSource = Objects.requireNonNull(DataTypes.BOOLEAN.sanitizeValue(SymbolEvaluator.evaluate(plannerContext.transactionContext(), dependencies.nodeContext(), swapTable.dropSource(), params, subQueryResults)), SwapTableAnalyzer.DROP_SOURCE + " option must be true or false, not null");
    RelationName source = swapTable.source().ident();
    SwapRelationsRequest request = new SwapRelationsRequest(Collections.singletonList(new RelationNameSwap(source, swapTable.target().ident())), dropSource ? Collections.singletonList(source) : emptyList());
    OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(consumer, r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L));
    dependencies.swapRelationsAction().execute(request, listener);
}
Also used : RelationNameSwap(io.crate.execution.ddl.RelationNameSwap) Row1(io.crate.data.Row1) OneRowActionListener(io.crate.execution.support.OneRowActionListener) SwapRelationsRequest(io.crate.execution.ddl.SwapRelationsRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RelationName(io.crate.metadata.RelationName)

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