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));
}
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());
}
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)));
}
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)));
}
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;
}
Aggregations