Search in sources :

Example 11 with LogicalPlan

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

the class MoveFilterBeneathWindowAggTest method test_filter_on_windows_function_partition_columns_is_moved.

@Test
public void test_filter_on_windows_function_partition_columns_is_moved() {
    var collect = e.logicalPlan("SELECT id 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("id = 10");
    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);
    var expectedPlan = "WindowAgg[id, row_number() OVER (PARTITION BY id)]\n" + "  └ Filter[(id = 10)]\n" + "    └ Collect[doc.t1 | [id] | true]";
    assertThat(newPlan, isPlan(expectedPlan));
}
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)

Example 12 with LogicalPlan

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

the class MoveFilterBeneathWindowAggTest method test_filters_combined_by_OR_cannot_be_moved.

@Test
public void test_filters_combined_by_OR_cannot_be_moved() {
    var collect = e.logicalPlan("SELECT id 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("ROW_NUMBER() OVER(PARTITION BY id) = 1 OR id = 10");
    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)

Example 13 with LogicalPlan

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

the class SingleRowSubselectPlannerTest method testSingleRowSubSelectAndDocKeysInWhereClause.

@Test
public void testSingleRowSubSelectAndDocKeysInWhereClause() throws Exception {
    LogicalPlan plan = e.logicalPlan("select (select 'foo' from sys.cluster) from users where id = 10");
    assertThat(plan.dependencies().keySet(), contains(instanceOf(RootRelationBoundary.class)));
}
Also used : LogicalPlan(io.crate.planner.operators.LogicalPlan) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 14 with LogicalPlan

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

the class SingleRowSubselectPlannerTest method testPlanSelectOnSysTablesWithSingleRowSubselectInWhere.

@Test
public void testPlanSelectOnSysTablesWithSingleRowSubselectInWhere() throws Exception {
    LogicalPlan plan = e.logicalPlan("select name from sys.cluster where name = (select 'foo')");
    assertThat(plan.dependencies().keySet(), contains(instanceOf(RootRelationBoundary.class)));
}
Also used : LogicalPlan(io.crate.planner.operators.LogicalPlan) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 15 with LogicalPlan

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

the class SQLExecutor method planInternal.

private <T> T planInternal(AnalyzedStatement analyzedStatement, UUID jobId, int fetchSize, Row params) {
    RoutingProvider routingProvider = new RoutingProvider(random.nextInt(), emptyList());
    PlannerContext plannerContext = new PlannerContext(planner.currentClusterState(), routingProvider, jobId, coordinatorTxnCtx, nodeCtx, fetchSize, null);
    Plan plan = planner.plan(analyzedStatement, plannerContext);
    if (plan instanceof LogicalPlan) {
        return (T) ((LogicalPlan) plan).build(plannerContext, Set.of(), new ProjectionBuilder(nodeCtx), TopN.NO_LIMIT, 0, null, null, params, new SubQueryResults(emptyMap()) {

            @Override
            public Object getSafe(SelectSymbol key) {
                return Literal.of(key.valueType(), null);
            }
        });
    }
    return (T) plan;
}
Also used : SelectSymbol(io.crate.expression.symbol.SelectSymbol) RoutingProvider(io.crate.metadata.RoutingProvider) PlannerContext(io.crate.planner.PlannerContext) SubQueryResults(io.crate.planner.operators.SubQueryResults) LogicalPlan(io.crate.planner.operators.LogicalPlan) CreateBlobTablePlan(io.crate.planner.node.ddl.CreateBlobTablePlan) LogicalPlan(io.crate.planner.operators.LogicalPlan) Plan(io.crate.planner.Plan) CreateTablePlan(io.crate.planner.node.ddl.CreateTablePlan) ProjectionBuilder(io.crate.execution.dsl.projection.builder.ProjectionBuilder)

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