Search in sources :

Example 6 with PlannerContext

use of io.crate.planner.PlannerContext in project crate by crate.

the class PreExecutionBenchmark method measure_parse_analyze_and_plan_simple_select.

@Benchmark
public Plan measure_parse_analyze_and_plan_simple_select() throws Exception {
    String sql = "select name from users";
    CoordinatorTxnCtx systemTransactionContext = CoordinatorTxnCtx.systemTransactionContext();
    Analysis analysis = new Analysis(systemTransactionContext, ParamTypeHints.EMPTY);
    AnalyzedStatement analyzedStatement = analyzer.analyzedStatement(SqlParser.createStatement(sql), analysis);
    var jobId = UUID.randomUUID();
    var routingProvider = new RoutingProvider(Randomness.get().nextInt(), planner.getAwarenessAttributes());
    var clusterState = clusterService.state();
    var txnCtx = CoordinatorTxnCtx.systemTransactionContext();
    var plannerContext = new PlannerContext(clusterState, routingProvider, jobId, txnCtx, nodeCtx, 0, null);
    return planner.plan(analyzedStatement, plannerContext);
}
Also used : RoutingProvider(io.crate.metadata.RoutingProvider) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) PlannerContext(io.crate.planner.PlannerContext) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 7 with PlannerContext

use of io.crate.planner.PlannerContext in project crate by crate.

the class SetSessionPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier executor, 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);
    SessionContext sessionContext = plannerContext.transactionContext().sessionContext();
    Assignment<Symbol> assignment = settings.get(0);
    String settingName = eval.apply(assignment.columnName()).toString();
    validateSetting(settingName);
    SessionSetting<?> sessionSetting = sessionSettingRegistry.settings().get(settingName);
    if (sessionSetting == null) {
        LOGGER.info("SET SESSION STATEMENT WILL BE IGNORED: {}", settingName);
    } else {
        sessionSetting.apply(sessionContext, assignment.expressions(), eval);
    }
    consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
}
Also used : CrateSettings(io.crate.metadata.settings.CrateSettings) SessionContext(io.crate.action.sql.SessionContext) SENTINEL(io.crate.data.SentinelRow.SENTINEL) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) SessionSetting(io.crate.metadata.settings.session.SessionSetting) Function(java.util.function.Function) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) Assignment(io.crate.sql.tree.Assignment) List(java.util.List) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Logger(org.apache.logging.log4j.Logger) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Locale(java.util.Locale) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) SessionSettingRegistry(io.crate.metadata.settings.session.SessionSettingRegistry) Symbol(io.crate.expression.symbol.Symbol) SessionContext(io.crate.action.sql.SessionContext)

Example 8 with PlannerContext

use of io.crate.planner.PlannerContext in project crate by crate.

the class MultiPhaseExecutor method execute.

public static CompletableFuture<SubQueryResults> execute(Map<LogicalPlan, SelectSymbol> dependencies, DependencyCarrier executor, PlannerContext plannerContext, Row params) {
    List<CompletableFuture<?>> dependencyFutures = new ArrayList<>(dependencies.size());
    IdentityHashMap<SelectSymbol, Object> valueBySubQuery = new IdentityHashMap<>();
    for (Map.Entry<LogicalPlan, SelectSymbol> entry : dependencies.entrySet()) {
        LogicalPlan depPlan = entry.getKey();
        SelectSymbol selectSymbol = entry.getValue();
        CollectingRowConsumer<?, ?> rowConsumer = getConsumer(selectSymbol.getResultType());
        depPlan.execute(executor, PlannerContext.forSubPlan(plannerContext), rowConsumer, params, SubQueryResults.EMPTY);
        dependencyFutures.add(rowConsumer.completionFuture().thenAccept(val -> {
            synchronized (valueBySubQuery) {
                valueBySubQuery.put(selectSymbol, val);
            }
        }));
    }
    return CompletableFuture.allOf(dependencyFutures.toArray(new CompletableFuture[0])).thenApply(ignored -> new SubQueryResults(valueBySubQuery));
}
Also used : SelectSymbol(io.crate.expression.symbol.SelectSymbol) LogicalPlan(io.crate.planner.operators.LogicalPlan) IdentityHashMap(java.util.IdentityHashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CollectingRowConsumer(io.crate.data.CollectingRowConsumer) ArrayList(java.util.ArrayList) DependencyCarrier(io.crate.planner.DependencyCarrier) List(java.util.List) Row(io.crate.data.Row) PlannerContext(io.crate.planner.PlannerContext) Map(java.util.Map) SelectSymbol(io.crate.expression.symbol.SelectSymbol) SubQueryResults(io.crate.planner.operators.SubQueryResults) FirstColumnConsumers(io.crate.execution.engine.FirstColumnConsumers) IdentityHashMap(java.util.IdentityHashMap) SubQueryResults(io.crate.planner.operators.SubQueryResults) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) LogicalPlan(io.crate.planner.operators.LogicalPlan) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Example 9 with PlannerContext

use of io.crate.planner.PlannerContext 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 10 with PlannerContext

use of io.crate.planner.PlannerContext 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)

Aggregations

PlannerContext (io.crate.planner.PlannerContext)40 Row (io.crate.data.Row)31 DependencyCarrier (io.crate.planner.DependencyCarrier)30 RowConsumer (io.crate.data.RowConsumer)29 Plan (io.crate.planner.Plan)28 SubQueryResults (io.crate.planner.operators.SubQueryResults)27 Row1 (io.crate.data.Row1)26 Symbol (io.crate.expression.symbol.Symbol)24 Function (java.util.function.Function)22 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)19 OneRowActionListener (io.crate.execution.support.OneRowActionListener)19 List (java.util.List)17 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)15 ArrayList (java.util.ArrayList)15 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)13 Map (java.util.Map)13 NodeContext (io.crate.metadata.NodeContext)12 DocTableInfo (io.crate.metadata.doc.DocTableInfo)12 Nullable (javax.annotation.Nullable)12 AbstractTableRelation (io.crate.analyze.relations.AbstractTableRelation)10