use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class WindowDefinitionTest method testUnboundedPrecedingUnboundedFollowingFrameIsAllowed.
@Test
public void testUnboundedPrecedingUnboundedFollowingFrameIsAllowed() {
Collect collect = e.plan("select sum(col1) over(RANGE BETWEEN UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING) FROM " + "unnest([1, 2, 1, 1, 1, 4])");
List<Projection> projections = collect.collectPhase().projections();
assertThat(projections.size(), is(2));
WindowAggProjection windowProjection = null;
for (Projection projection : projections) {
if (projection instanceof WindowAggProjection) {
windowProjection = (WindowAggProjection) projection;
break;
}
}
assertThat(windowProjection, is(notNullValue()));
List<? extends Symbol> outputs = windowProjection.outputs();
// IC and window function
assertThat(outputs.size(), is(2));
WindowFunction windowFunction = null;
for (Symbol output : outputs) {
if (output instanceof WindowFunction) {
windowFunction = (WindowFunction) output;
}
}
assertThat(windowFunction, is(notNullValue()));
assertThat(windowFunction.windowDefinition().windowFrameDefinition().start().type(), is(UNBOUNDED_PRECEDING));
assertThat(windowFunction.windowDefinition().windowFrameDefinition().end().type(), is(UNBOUNDED_FOLLOWING));
}
use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class Merge method ensureOnHandler.
/**
* Wrap the subPlan into a Merge plan if it isn't executed on the handler.
* @param projections projections to be applied on the subPlan or merge plan.
* These projections must not affect the limit, offset, order by or numOutputs
*
* If the subPlan contains a limit/offset or orderBy in its resultDescription this method will
* add a TopNProjection AFTER the projections.
*/
public static ExecutionPlan ensureOnHandler(ExecutionPlan subExecutionPlan, PlannerContext plannerContext, List<Projection> projections) {
ResultDescription resultDescription = subExecutionPlan.resultDescription();
assert resultDescription != null : "all plans must have a result description. Plan without: " + subExecutionPlan;
// If a sub-Plan applies a limit it is usually limit+offset
// So even if the execution is on the handler the limit may be too large and the final limit needs to be applied as well
Projection topN = ProjectionBuilder.topNOrEvalIfNeeded(resultDescription.limit(), resultDescription.offset(), resultDescription.numOutputs(), resultDescription.streamOutputs());
if (ExecutionPhases.executesOnHandler(plannerContext.handlerNode(), resultDescription.nodeIds())) {
return addProjections(subExecutionPlan, projections, resultDescription, topN);
}
maybeUpdatePageSizeHint(subExecutionPlan, resultDescription.maxRowsPerNode());
Collection<String> handlerNodeIds = Collections.singletonList(plannerContext.handlerNode());
MergePhase mergePhase = new MergePhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "mergeOnHandler", resultDescription.nodeIds().size(), 1, handlerNodeIds, resultDescription.streamOutputs(), addProjection(projections, topN), DistributionInfo.DEFAULT_BROADCAST, resultDescription.orderBy());
return new Merge(subExecutionPlan, mergePhase, TopN.NO_LIMIT, 0, resultDescription.numOutputs(), resultDescription.limit(), resultDescription.orderBy());
}
use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class SubQueryPlannerTest method testJoinWithAggregationOnSubSelectsWithLimitAndOffset.
@Test
public void testJoinWithAggregationOnSubSelectsWithLimitAndOffset() throws Exception {
Join join = e.plan("select t1.a, count(*) from " + " (select i, a from t1 order by a limit 10 offset 2) t1 " + "join" + " (select i from t2 order by i desc limit 5 offset 5) t2 " + "on t1.i = t2.i " + "group by t1.a");
QueryThenFetch qtf = (QueryThenFetch) join.left();
Collect left = (Collect) qtf.subPlan();
assertThat("1 node, otherwise mergePhases would be required", left.nodeIds().size(), is(1));
assertThat(((RoutedCollectPhase) left.collectPhase()).orderBy(), isSQL("doc.t1.a"));
assertThat(left.collectPhase().projections(), contains(isTopN(10, 2), instanceOf(FetchProjection.class)));
assertThat(left.collectPhase().toCollect(), isSQL("doc.t1._fetchid, doc.t1.a"));
Collect right = (Collect) join.right();
assertThat("1 node, otherwise mergePhases would be required", right.nodeIds().size(), is(1));
assertThat(((RoutedCollectPhase) right.collectPhase()).orderBy(), isSQL("doc.t2.i DESC"));
assertThat(right.collectPhase().projections(), contains(isTopN(5, 5)));
List<Projection> nlProjections = join.joinPhase().projections();
assertThat(nlProjections, contains(instanceOf(EvalProjection.class), instanceOf(GroupProjection.class)));
}
use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class GlobalAggregatePlannerTest method testAggregateOnSubQueryNoFetchBecauseColumnInUse.
@Test
public void testAggregateOnSubQueryNoFetchBecauseColumnInUse() throws Exception {
Collect plan = e.plan("select sum(x) from (select x, i from t1 order by x limit 10) ti");
List<Projection> projections = plan.collectPhase().projections();
assertThat(projections, contains(instanceOf(TopNProjection.class), instanceOf(AggregationProjection.class)));
}
Aggregations