use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestConnectorOptimization method testMultipleConnectors.
@Test
public void testMultipleConnectors() {
PlanNode plan = output(union(tableScan("cat1", "a", "b"), tableScan("cat2", "a", "b"), tableScan("cat3", "a", "b"), tableScan("cat4", "a", "b"), tableScan("cat2", "a", "b"), tableScan("cat1", "a", "b"), values("a", "b")), "a");
PlanNode actual = optimize(plan, ImmutableMap.of());
assertEquals(actual, plan);
actual = optimize(plan, ImmutableMap.of(new ConnectorId("cat2"), ImmutableSet.of(noop())));
assertEquals(actual, plan);
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestConnectorOptimization method testPlanUpdateWithComplexStructures.
@Test
public void testPlanUpdateWithComplexStructures() {
PlanNode plan = output(union(filter(tableScan("cat1", "a", "b"), TRUE_CONSTANT), filter(tableScan("cat2", "a", "b"), TRUE_CONSTANT), union(filter(tableScan("cat3", "a", "b"), TRUE_CONSTANT), union(filter(tableScan("cat4", "a", "b"), TRUE_CONSTANT), filter(tableScan("cat1", "a", "b"), TRUE_CONSTANT))), filter(tableScan("cat2", "a", "b"), TRUE_CONSTANT), union(filter(tableScan("cat1", "a", "b"), TRUE_CONSTANT))), "a");
PlanNode actual = optimize(plan, ImmutableMap.of());
assertEquals(actual, plan);
// force updating every leaf node
actual = optimize(plan, ImmutableMap.of(new ConnectorId("cat1"), ImmutableSet.of(filterPushdown()), new ConnectorId("cat2"), ImmutableSet.of(filterPushdown()), new ConnectorId("cat3"), ImmutableSet.of(filterPushdown()), new ConnectorId("cat4"), ImmutableSet.of(filterPushdown())));
// assert all filters removed
assertPlanMatch(actual, PlanMatchPattern.output(PlanMatchPattern.union(SimpleTableScanMatcher.tableScan("cat1", TRUE_CONSTANT), SimpleTableScanMatcher.tableScan("cat2", TRUE_CONSTANT), PlanMatchPattern.union(SimpleTableScanMatcher.tableScan("cat3", TRUE_CONSTANT), PlanMatchPattern.union(SimpleTableScanMatcher.tableScan("cat4", TRUE_CONSTANT), SimpleTableScanMatcher.tableScan("cat1", TRUE_CONSTANT))), SimpleTableScanMatcher.tableScan("cat2", TRUE_CONSTANT), PlanMatchPattern.union(SimpleTableScanMatcher.tableScan("cat1", TRUE_CONSTANT)))));
}
use of com.facebook.presto.spi.plan.PlanNode 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.spi.plan.PlanNode in project presto by prestodb.
the class TestTranslateExpressions method testTranslateIntermediateAggregationWithLambda.
@Test
public void testTranslateIntermediateAggregationWithLambda() {
PlanNode result = tester().assertThat(new TranslateExpressions(METADATA, new SqlParser()).aggregationRowExpressionRewriteRule()).on(p -> p.aggregation(builder -> builder.globalGrouping().addAggregation(variable("reduce_agg", INTEGER), new AggregationNode.Aggregation(new CallExpression("reduce_agg", REDUCE_AGG, INTEGER, ImmutableList.of(castToRowExpression(expression("input")), castToRowExpression(expression("(x,y) -> x*y")), castToRowExpression(expression("(a,b) -> a*b")))), Optional.of(castToRowExpression(expression("input > 10"))), Optional.empty(), false, Optional.empty())).source(p.values(p.variable("input", INTEGER))))).get();
AggregationNode.Aggregation translated = ((AggregationNode) result).getAggregations().get(variable("reduce_agg", INTEGER));
assertEquals(translated, new AggregationNode.Aggregation(new CallExpression("reduce_agg", REDUCE_AGG, INTEGER, ImmutableList.of(variable("input", INTEGER), new LambdaDefinitionExpression(Optional.empty(), ImmutableList.of(INTEGER, INTEGER), ImmutableList.of("x", "y"), multiply(variable("x", INTEGER), variable("y", INTEGER))), new LambdaDefinitionExpression(Optional.empty(), ImmutableList.of(INTEGER, INTEGER), ImmutableList.of("a", "b"), multiply(variable("a", INTEGER), variable("b", INTEGER))))), Optional.of(greaterThan(variable("input", INTEGER), constant(10L, INTEGER))), Optional.empty(), false, Optional.empty()));
assertFalse(isUntranslated(translated));
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestTranslateExpressions method testTranslateAggregationWithLambda.
@Test
public void testTranslateAggregationWithLambda() {
PlanNode result = tester().assertThat(new TranslateExpressions(METADATA, new SqlParser()).aggregationRowExpressionRewriteRule()).on(p -> p.aggregation(builder -> builder.globalGrouping().addAggregation(variable("reduce_agg", INTEGER), new AggregationNode.Aggregation(new CallExpression("reduce_agg", REDUCE_AGG, INTEGER, ImmutableList.of(castToRowExpression(expression("input")), castToRowExpression(expression("0")), castToRowExpression(expression("(x,y) -> x*y")), castToRowExpression(expression("(a,b) -> a*b")))), Optional.of(castToRowExpression(expression("input > 10"))), Optional.empty(), false, Optional.empty())).source(p.values(p.variable("input", INTEGER))))).get();
// TODO migrate this to RowExpressionMatcher
AggregationNode.Aggregation translated = ((AggregationNode) result).getAggregations().get(variable("reduce_agg", INTEGER));
assertEquals(translated, new AggregationNode.Aggregation(new CallExpression("reduce_agg", REDUCE_AGG, INTEGER, ImmutableList.of(variable("input", INTEGER), constant(0L, INTEGER), new LambdaDefinitionExpression(Optional.empty(), ImmutableList.of(INTEGER, INTEGER), ImmutableList.of("x", "y"), multiply(variable("x", INTEGER), variable("y", INTEGER))), new LambdaDefinitionExpression(Optional.empty(), ImmutableList.of(INTEGER, INTEGER), ImmutableList.of("a", "b"), multiply(variable("a", INTEGER), variable("b", INTEGER))))), Optional.of(greaterThan(variable("input", INTEGER), constant(10L, INTEGER))), Optional.empty(), false, Optional.empty()));
assertFalse(isUntranslated(translated));
}
Aggregations