use of com.facebook.presto.SystemSessionProperties.AGGREGATION_IF_TO_FILTER_REWRITE_STRATEGY 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")))));
}
Aggregations