use of com.facebook.presto.sql.planner.assertions.ExpressionMatcher in project presto by prestodb.
the class TestRewriteAggregationIfToFilter method testRewriteStrategies.
@Test
public void testRewriteStrategies() {
Function<PlanBuilder, PlanNode> planProvider = p -> {
VariableReferenceExpression a = p.variable("a");
VariableReferenceExpression column0 = p.variable("column0", BIGINT);
return p.aggregation(ap -> ap.globalGrouping().step(AggregationNode.Step.FINAL).addAggregation(p.variable("expr0"), p.rowExpression("SUM(a)")).source(p.project(assignment(a, p.rowExpression("IF(column0 > 1, column0)")), p.values(column0))));
};
tester().assertThat(new RewriteAggregationIfToFilter(getFunctionManager())).setSystemProperty(AGGREGATION_IF_TO_FILTER_REWRITE_STRATEGY, "disabled").on(planProvider).doesNotFire();
tester().assertThat(new RewriteAggregationIfToFilter(getFunctionManager())).setSystemProperty(AGGREGATION_IF_TO_FILTER_REWRITE_STRATEGY, "filter_with_if").on(planProvider).matches(aggregation(globalAggregation(), ImmutableMap.of(Optional.of("expr0"), functionCall("sum", ImmutableList.of("a"))), ImmutableMap.of(new Symbol("expr0"), new Symbol("greater_than")), Optional.empty(), AggregationNode.Step.FINAL, filter("greater_than", project(new ImmutableMap.Builder<String, ExpressionMatcher>().put("a", expression("IF(column0 > 1, column0)")).put("greater_than", expression("column0 > 1")).build(), values("column0")))));
tester().assertThat(new RewriteAggregationIfToFilter(getFunctionManager())).setSystemProperty(AGGREGATION_IF_TO_FILTER_REWRITE_STRATEGY, "unwrap_if_safe").on(planProvider).matches(aggregation(globalAggregation(), ImmutableMap.of(Optional.of("expr0"), functionCall("sum", ImmutableList.of("a"))), ImmutableMap.of(new Symbol("expr0"), new Symbol("greater_than")), Optional.empty(), AggregationNode.Step.FINAL, filter("greater_than", project(new ImmutableMap.Builder<String, ExpressionMatcher>().put("a", expression("IF(column0 > 1, column0)")).put("greater_than", expression("column0 > 1")).build(), values("column0")))));
tester().assertThat(new RewriteAggregationIfToFilter(getFunctionManager())).setSystemProperty(AGGREGATION_IF_TO_FILTER_REWRITE_STRATEGY, "unwrap_if").on(planProvider).matches(aggregation(globalAggregation(), ImmutableMap.of(Optional.of("expr0"), functionCall("sum", ImmutableList.of("column0_0"))), ImmutableMap.of(new Symbol("expr0"), new Symbol("greater_than")), Optional.empty(), AggregationNode.Step.FINAL, filter("greater_than", project(new ImmutableMap.Builder<String, ExpressionMatcher>().put("a", expression("IF(column0 > 1, column0)")).put("greater_than", expression("column0 > 1")).put("column0_0", expression("column0")).build(), values("column0")))));
}
use of com.facebook.presto.sql.planner.assertions.ExpressionMatcher in project presto by prestodb.
the class TestLogicalPlanner method testOffset.
@Test
public void testOffset() {
Session enableOffset = Session.builder(this.getQueryRunner().getDefaultSession()).setSystemProperty(OFFSET_CLAUSE_ENABLED, "true").build();
assertPlanWithSession("SELECT name FROM nation OFFSET 2 ROWS", enableOffset, true, any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name")), filter("(row_num > BIGINT '2')", rowNumber(pattern -> pattern.partitionBy(ImmutableList.of()), any(tableScan("nation", ImmutableMap.of("NAME", "name")))).withAlias("row_num", new RowNumberSymbolMatcher())))));
assertPlanWithSession("SELECT name FROM nation ORDER BY regionkey OFFSET 2 ROWS", enableOffset, true, any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name")), filter("row_num > BIGINT '2'", rowNumber(pattern -> pattern.partitionBy(ImmutableList.of()), anyTree(sort(ImmutableList.of(sort("regionkey", ASCENDING, LAST)), any(tableScan("nation", ImmutableMap.of("name", "name", "regionkey", "regionkey")))))).withAlias("row_num", new RowNumberSymbolMatcher())))));
}
Aggregations