private ProjectNode buildProjectedTopN(PlanBuilder planBuilder, Predicate<Symbol> projectionTopN) { Symbol a = planBuilder.symbol("a"); Symbol b = planBuilder.symbol("b"); return planBuilder.project( Assignments.identity(ImmutableList.of(a, b).stream().filter(projectionTopN).collect(toImmutableSet())), planBuilder.topN( COUNT, ImmutableList.of(b), planBuilder.values(a, b))); } }
@Test public void testLimitOnTopOfValues() { PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata()); assertEquals( extractCardinality(planBuilder.limit(3, planBuilder.values(emptyList(), ImmutableList.of(emptyList())))), Range.singleton(1L)); assertEquals( extractCardinality(planBuilder.limit(3, planBuilder.values(emptyList(), ImmutableList.of(emptyList(), emptyList(), emptyList(), emptyList())))), Range.singleton(3L)); } }
@Test public void testSingleThreadFinalAggregationInTheSameStageAsPartialAggregation() { PlanNode root = builder.aggregation( af -> af.step(FINAL) .groupingSets(groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))) .source(builder.aggregation(ap -> ap .step(PARTIAL) .groupingSets(groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))) .source(builder.values())))); validatePlan(root, true); }
private ProjectNode buildProjectedAggregation(PlanBuilder planBuilder, Predicate<Symbol> projectionFilter) { Symbol a = planBuilder.symbol("a"); Symbol b = planBuilder.symbol("b"); Symbol key = planBuilder.symbol("key"); return planBuilder.project( Assignments.identity(ImmutableList.of(a, b).stream().filter(projectionFilter).collect(toImmutableSet())), planBuilder.aggregation(aggregationBuilder -> aggregationBuilder .source(planBuilder.values(key)) .singleGroupingSet(key) .addAggregation(a, planBuilder.expression("count()"), ImmutableList.of()) .addAggregation(b, planBuilder.expression("count()"), ImmutableList.of()))); } }
@Test public void doesNotFireOnPlanWithoutLateralNode() { tester().assertThat(rule) .on(p -> p.values(p.symbol("a"))) .doesNotFire(); }
@Test public void testDoesNotFire() { tester().assertThat(new TransformCorrelatedSingleRowSubqueryToProject()) .on(p -> p.values(p.symbol("a"))) .doesNotFire(); }
@Test public void testValueExpressionRewrite() { tester().assertThat(zeroRewriter.valuesExpressionRewrite()) .on(p -> p.values( ImmutableList.<Symbol>of(p.symbol("a")), ImmutableList.of((ImmutableList.of(PlanBuilder.expression("1")))))) .matches( values(ImmutableList.of("a"), ImmutableList.of(ImmutableList.of(new LongLiteral("0"))))); }
@Test public void testDoesNotFire() { tester().assertThat(new RemoveUnreferencedScalarLateralNodes()) .on(p -> p.lateral( emptyList(), p.values(), p.values())) .doesNotFire(); } }
@Test public void doesNotFireOnPlanWithoutWindowFunctions() { tester().assertThat(new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(0)) .on(p -> p.values(p.symbol("a"))) .doesNotFire(); }
@Test public void testPlanWithoutWindowNode() { tester().assertThat(new GatherAndMergeWindows.MergeAdjacentWindowsOverProjects(0)) .on(p -> p.values(p.symbol("a"))) .doesNotFire(); }
@Test public void doesNotFireIfNoTableScan() { for (Rule<?> rule : pickTableLayout.rules()) { tester().assertThat(rule) .on(p -> p.values(p.symbol("a", BIGINT))) .doesNotFire(); } }
@Test public void testCrossJoinDoesNotFire() { tester().assertThat(new PruneJoinColumns()) .on(p -> { Symbol leftValue = p.symbol("leftValue"); Symbol rightValue = p.symbol("rightValue"); return p.join( JoinNode.Type.INNER, p.values(leftValue), p.values(rightValue), ImmutableList.of(), ImmutableList.of(leftValue, rightValue), Optional.empty(), Optional.empty(), Optional.empty()); }) .doesNotFire(); }