use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class WhereClauseOptimizerTest method optimize.
private WhereClauseOptimizer.DetailedQuery optimize(String statement) {
QueriedSelectRelation queriedTable = e.analyze(statement);
DocTableRelation table = ((DocTableRelation) queriedTable.from().get(0));
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(e.nodeCtx, RowGranularity.CLUSTER, null, table);
return WhereClauseOptimizer.optimize(normalizer, queriedTable.where(), table.tableInfo(), e.getPlannerContext(clusterService.state()).transactionContext(), e.nodeCtx);
}
use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class RelationNormalizerTest method testOrderByLimitsNotMerged.
@Test
public void testOrderByLimitsNotMerged() throws Exception {
QueriedRelation relation = normalize("select * from (" + "select * from (" + "select * from t1 order by a limit 10 offset 5" + ") as tt" + ") as ttt order by a desc limit 5");
assertThat(relation, instanceOf(QueriedSelectRelation.class));
QueriedSelectRelation outerRelation = (QueriedSelectRelation) relation;
assertThat(outerRelation.querySpec(), isSQL("SELECT io.crate.analyze.QueriedSelectRelation.a, " + "io.crate.analyze.QueriedSelectRelation.x, " + "io.crate.analyze.QueriedSelectRelation.i " + "ORDER BY io.crate.analyze.QueriedSelectRelation.a DESC LIMIT 5"));
assertThat(outerRelation.subRelation(), instanceOf(QueriedDocTable.class));
assertThat(outerRelation.subRelation().querySpec(), isSQL("SELECT doc.t1.a, doc.t1.x, doc.t1.i ORDER BY doc.t1.a LIMIT 10 OFFSET 5"));
}
use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class RelationNormalizerTest method testOrderByLimitsOnInnerNotMerged.
@Test
public void testOrderByLimitsOnInnerNotMerged() throws Exception {
QueriedRelation relation = normalize("select * from (" + "select * from (" + "select * from t1 order by a limit 10" + ") as tt" + ") as ttt order by x");
assertThat(relation, instanceOf(QueriedSelectRelation.class));
QueriedSelectRelation outerRelation = (QueriedSelectRelation) relation;
assertThat(outerRelation.querySpec(), isSQL("SELECT io.crate.analyze.QueriedSelectRelation.a, " + "io.crate.analyze.QueriedSelectRelation.x, " + "io.crate.analyze.QueriedSelectRelation.i ORDER BY io.crate.analyze.QueriedSelectRelation.x"));
assertThat(outerRelation.subRelation(), instanceOf(QueriedDocTable.class));
assertThat(outerRelation.subRelation().querySpec(), isSQL("SELECT doc.t1.a, doc.t1.x, doc.t1.i ORDER BY doc.t1.a LIMIT 10"));
}
use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class LimitTest method testLimitOnLimitOperator.
@Test
public void testLimitOnLimitOperator() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
QueriedSelectRelation queriedDocTable = e.analyze("select name from users");
LogicalPlan plan = Limit.create(Limit.create(Collect.create(((AbstractTableRelation<?>) queriedDocTable.from().get(0)), queriedDocTable.outputs(), new WhereClause(queriedDocTable.where()), new TableStats(), null), Literal.of(10L), Literal.of(5L)), Literal.of(20L), Literal.of(7L));
assertThat(plan, isPlan("Limit[20::bigint;7::bigint]\n" + " └ Limit[10::bigint;5::bigint]\n" + " └ Collect[doc.users | [name] | true]"));
PlannerContext ctx = e.getPlannerContext(clusterService.state());
Merge merge = (Merge) plan.build(ctx, Set.of(), new ProjectionBuilder(e.nodeCtx), TopN.NO_LIMIT, 0, null, null, Row.EMPTY, SubQueryResults.EMPTY);
io.crate.planner.node.dql.Collect collect = (io.crate.planner.node.dql.Collect) merge.subPlan();
assertThat(collect.collectPhase().projections(), contains(ProjectionMatchers.isTopN(15, 0)));
// noinspection unchecked
assertThat(merge.mergePhase().projections(), contains(ProjectionMatchers.isTopN(10, 5), ProjectionMatchers.isTopN(20, 7)));
}
use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class CollectTest method test.
@Test
public void test() throws Exception {
var e = SQLExecutor.builder(clusterService).addTable("CREATE TABLE t (x int)").build();
TableStats tableStats = new TableStats();
PlannerContext plannerCtx = e.getPlannerContext(clusterService.state());
ProjectionBuilder projectionBuilder = new ProjectionBuilder(e.nodeCtx);
QueriedSelectRelation analyzedRelation = e.analyze("SELECT 123 AS alias, 456 AS alias2 FROM t ORDER BY alias, 2");
LogicalPlanner logicalPlanner = new LogicalPlanner(e.nodeCtx, tableStats, () -> clusterService.state().nodes().getMinNodeVersion());
LogicalPlan operator = logicalPlanner.plan(analyzedRelation, plannerCtx);
ExecutionPlan build = operator.build(plannerCtx, Set.of(), projectionBuilder, -1, 0, null, null, Row.EMPTY, SubQueryResults.EMPTY);
assertThat((((RoutedCollectPhase) ((io.crate.planner.node.dql.Collect) build).collectPhase())).orderBy(), is(nullValue()));
}
Aggregations