public RuleAssert(Metadata metadata, StatsCalculator statsCalculator, CostCalculator costCalculator, Session session, Rule rule, TransactionManager transactionManager, AccessControl accessControl) { this.metadata = metadata; this.statsCalculator = new TestingStatsCalculator(statsCalculator); this.costCalculator = costCalculator; this.session = session; this.rule = rule; this.transactionManager = transactionManager; this.accessControl = accessControl; }
public ValuesNode values(PlanNodeId id, Symbol... columns) { return values(id, 0, columns); }
public Symbol symbol(String name) { return symbol(name, BIGINT); }
@Test public void doesNotFireOnPlanWithoutLateralNode() { tester().assertThat(rule) .on(p -> p.values(p.symbol("a"))) .doesNotFire(); }
@Test public void testDistinctWithFilter() { tester().assertThat(new SingleDistinctAggregationToGroupBy()) .on(p -> p.aggregation(builder -> builder .globalGrouping() .addAggregation(p.symbol("output"), expression("count(DISTINCT input1) filter (where input2 > 0)"), ImmutableList.of(BIGINT)) .source( p.values( p.symbol("input1"), p.symbol("input2"))))) .doesNotFire(); }
@Test public void testDoesNotFire() { tester().assertThat(new RemoveTrivialFilters()) .on(p -> p.filter(p.expression("1 = 1"), p.values())) .doesNotFire(); }
@Test public void testDoesNotFireForUnfilteredJoin() { tester().assertThat(canonicalizeExpressions.joinExpressionRewrite()) .on(p -> p.join(INNER, p.values(), p.values())) .doesNotFire(); }
public ExchangeNode gatheringExchange(ExchangeNode.Scope scope, PlanNode child) { return exchange(builder -> builder.type(ExchangeNode.Type.GATHER) .scope(scope) .singleDistributionPartitioningScheme(child.getOutputSymbols()) .addSource(child) .addInputsSet(child.getOutputSymbols())); }
@Test public void doesNotFireOnCorrelatedNonScalar() { tester().assertThat(rule) .on(p -> p.lateral( ImmutableList.of(p.symbol("corr")), p.values(p.symbol("corr")), p.values(p.symbol("a")))) .doesNotFire(); }
@Test public void testSingleDistinct() { tester().assertThat(new MultipleDistinctAggregationToMarkDistinct()) .on(p -> p.aggregation(builder -> builder .globalGrouping() .addAggregation(p.symbol("output1"), expression("count(DISTINCT input1)"), ImmutableList.of(BIGINT)) .source( p.values( p.symbol("input1"), p.symbol("input2"))))) .doesNotFire(); }
@Test public void testDoesNotFireForExpressionsInCanonicalForm() { tester().assertThat(canonicalizeExpressions.filterExpressionRewrite()) .on(p -> p.filter(FALSE_LITERAL, p.values())) .doesNotFire(); }
@Test public void testDoesNotFireForCanonicalExpressions() { tester().assertThat(canonicalizeExpressions.joinExpressionRewrite()) .on(p -> p.join(INNER, p.values(), p.values(), FALSE_LITERAL)) .doesNotFire(); } }
@Test public void doesNotFireOnUncorrelated() { tester().assertThat(rule) .on(p -> p.lateral( ImmutableList.<Symbol>of(), p.values(p.symbol("a")), p.values(ImmutableList.of(p.symbol("b")), ImmutableList.of(expressions("1"))))) .doesNotFire(); }
@Test public void testMultipleAggregations() { tester().assertThat(new MultipleDistinctAggregationToMarkDistinct()) .on(p -> p.aggregation(builder -> builder .globalGrouping() .addAggregation(p.symbol("output1"), expression("count(DISTINCT input)"), ImmutableList.of(BIGINT)) .addAggregation(p.symbol("output2"), expression("sum(DISTINCT input)"), ImmutableList.of(BIGINT)) .source( p.values(p.symbol("input"))))) .doesNotFire(); }
@Test public void testDoesNotFire() { tester().assertThat(new EvaluateZeroLimit()) .on(p -> p.limit( 1, p.values(p.symbol("a")))) .doesNotFire(); }
@Test public void testDoesNotFire() { tester().assertThat(new EvaluateZeroSample()) .on(p -> p.sample( 0.15, Type.BERNOULLI, p.values(p.symbol("a")))) .doesNotFire(); }
@Test public void testDoesNotFire() { tester().assertThat(new RemoveFullSample()) .on(p -> p.sample( 0.15, Type.BERNOULLI, 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 doesNotFireOnPlanWithoutWindowFunctions() { tester().assertThat(new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(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(); } }