Search in sources :

Example 6 with LogicalPlan

use of io.crate.planner.operators.LogicalPlan in project crate by crate.

the class FilterOnJoinsUtil method moveQueryBelowJoin.

static LogicalPlan moveQueryBelowJoin(Symbol query, LogicalPlan join) {
    if (!WhereClause.canMatch(query)) {
        return join.replaceSources(List.of(getNewSource(query, join.sources().get(0)), getNewSource(query, join.sources().get(1))));
    }
    Map<Set<RelationName>, Symbol> splitQuery = QuerySplitter.split(query);
    int initialParts = splitQuery.size();
    if (splitQuery.size() == 1 && splitQuery.keySet().iterator().next().size() > 1) {
        return null;
    }
    assert join.sources().size() == 2 : "Join operator must only have 2 children, LHS and RHS";
    LogicalPlan lhs = join.sources().get(0);
    LogicalPlan rhs = join.sources().get(1);
    Set<RelationName> leftName = lhs.getRelationNames();
    Set<RelationName> rightName = rhs.getRelationNames();
    Symbol queryForLhs = splitQuery.remove(leftName);
    Symbol queryForRhs = splitQuery.remove(rightName);
    LogicalPlan newLhs = getNewSource(queryForLhs, lhs);
    LogicalPlan newRhs = getNewSource(queryForRhs, rhs);
    LogicalPlan newJoin = join.replaceSources(List.of(newLhs, newRhs));
    if (splitQuery.isEmpty()) {
        return newJoin;
    } else if (initialParts == splitQuery.size()) {
        return null;
    } else {
        return new Filter(newJoin, AndOperator.join(splitQuery.values()));
    }
}
Also used : Set(java.util.Set) Filter(io.crate.planner.operators.Filter) Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) LogicalPlan(io.crate.planner.operators.LogicalPlan)

Example 7 with LogicalPlan

use of io.crate.planner.operators.LogicalPlan in project crate by crate.

the class MoveOrderBeneathUnion method apply.

@Override
public LogicalPlan apply(Order order, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
    Union union = captures.get(unionCapture);
    List<LogicalPlan> unionSources = union.sources();
    assert unionSources.size() == 2 : "A UNION must have exactly 2 unionSources";
    Order lhsOrder = updateSources(order, unionSources.get(0));
    Order rhsOrder = updateSources(order, unionSources.get(1));
    return union.replaceSources(List.of(lhsOrder, rhsOrder));
}
Also used : Order(io.crate.planner.operators.Order) LogicalPlan(io.crate.planner.operators.LogicalPlan) Union(io.crate.planner.operators.Union)

Example 8 with LogicalPlan

use of io.crate.planner.operators.LogicalPlan in project crate by crate.

the class SubqueryPlanner method planSubquery.

private void planSubquery(SelectSymbol selectSymbol, Map<LogicalPlan, SelectSymbol> subQueries) {
    LogicalPlan subPlan = planSubSelects.apply(selectSymbol);
    subQueries.put(subPlan, selectSymbol);
}
Also used : LogicalPlan(io.crate.planner.operators.LogicalPlan)

Example 9 with LogicalPlan

use of io.crate.planner.operators.LogicalPlan in project crate by crate.

the class InsertFromSubQueryPlanner method plan.

public static LogicalPlan plan(AnalyzedInsertStatement statement, PlannerContext plannerContext, LogicalPlanner logicalPlanner, SubqueryPlanner subqueryPlanner) {
    if (statement.outputs() != null && !plannerContext.clusterState().getNodes().getMinNodeVersion().onOrAfter(Version.V_4_2_0)) {
        throw new UnsupportedFeatureException(RETURNING_VERSION_ERROR_MSG);
    }
    List<Reference> targetColsExclPartitionCols = new ArrayList<>(statement.columns().size() - statement.tableInfo().partitionedBy().size());
    for (Reference column : statement.columns()) {
        if (statement.tableInfo().partitionedBy().contains(column.column())) {
            continue;
        }
        targetColsExclPartitionCols.add(column);
    }
    List<Symbol> columnSymbols = InputColumns.create(targetColsExclPartitionCols, new InputColumns.SourceSymbols(statement.columns()));
    // if fields are null default to number of rows imported
    var outputs = statement.outputs() == null ? List.of(new InputColumn(0, DataTypes.LONG)) : statement.outputs();
    ColumnIndexWriterProjection indexWriterProjection = new ColumnIndexWriterProjection(statement.tableInfo().ident(), null, statement.tableInfo().primaryKey(), statement.columns(), targetColsExclPartitionCols, columnSymbols, statement.isIgnoreDuplicateKeys(), statement.onDuplicateKeyAssignments(), statement.primaryKeySymbols(), statement.partitionedBySymbols(), statement.tableInfo().clusteredBy(), statement.clusteredBySymbol(), Settings.EMPTY, statement.tableInfo().isPartitioned(), outputs, statement.outputs() == null ? List.of() : statement.outputs());
    LogicalPlan plannedSubQuery = logicalPlanner.plan(statement.subQueryRelation(), plannerContext, subqueryPlanner, true);
    EvalProjection castOutputs = EvalProjection.castValues(Symbols.typeView(statement.columns()), plannedSubQuery.outputs());
    return new Insert(plannedSubQuery, indexWriterProjection, castOutputs);
}
Also used : InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) UnsupportedFeatureException(io.crate.exceptions.UnsupportedFeatureException) Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) Insert(io.crate.planner.operators.Insert) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) InputColumn(io.crate.expression.symbol.InputColumn) LogicalPlan(io.crate.planner.operators.LogicalPlan)

Example 10 with LogicalPlan

use of io.crate.planner.operators.LogicalPlan in project crate by crate.

the class MoveFilterBeneathWindowAggTest method test_filter_containing_columns_not_part_of_the_window_partition_cannot_be_moved.

@Test
public void test_filter_containing_columns_not_part_of_the_window_partition_cannot_be_moved() {
    var collect = e.logicalPlan("SELECT id, x FROM t1");
    WindowFunction windowFunction = (WindowFunction) e.asSymbol("ROW_NUMBER() OVER(PARTITION by id)");
    WindowAgg windowAgg = (WindowAgg) WindowAgg.create(collect, List.of(windowFunction));
    Symbol query = e.asSymbol("x = 1");
    Filter filter = new Filter(windowAgg, query);
    var rule = new MoveFilterBeneathWindowAgg();
    Match<Filter> match = rule.pattern().accept(filter, Captures.empty());
    assertThat(match.isPresent(), is(true));
    assertThat(match.value(), Matchers.sameInstance(filter));
    LogicalPlan newPlan = rule.apply(match.value(), match.captures(), new TableStats(), CoordinatorTxnCtx.systemTransactionContext(), e.nodeCtx);
    assertThat(newPlan, nullValue());
}
Also used : WindowFunction(io.crate.expression.symbol.WindowFunction) WindowAgg(io.crate.planner.operators.WindowAgg) Filter(io.crate.planner.operators.Filter) Symbol(io.crate.expression.symbol.Symbol) LogicalPlan(io.crate.planner.operators.LogicalPlan) TableStats(io.crate.statistics.TableStats) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

LogicalPlan (io.crate.planner.operators.LogicalPlan)28 Symbol (io.crate.expression.symbol.Symbol)12 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)11 Test (org.junit.Test)11 Filter (io.crate.planner.operators.Filter)9 TableStats (io.crate.statistics.TableStats)7 WindowFunction (io.crate.expression.symbol.WindowFunction)6 WindowAgg (io.crate.planner.operators.WindowAgg)6 ArrayList (java.util.ArrayList)5 SelectSymbol (io.crate.expression.symbol.SelectSymbol)4 List (java.util.List)4 Reference (io.crate.metadata.Reference)3 ExecutionPlan (io.crate.planner.ExecutionPlan)3 DocTableRelation (io.crate.analyze.relations.DocTableRelation)2 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)2 Row (io.crate.data.Row)2 Row1 (io.crate.data.Row1)2 RowConsumer (io.crate.data.RowConsumer)2 UnsupportedFeatureException (io.crate.exceptions.UnsupportedFeatureException)2 NodeOperationTree (io.crate.execution.dsl.phases.NodeOperationTree)2