Search in sources :

Example 36 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestPlanRemoteProjections method testRemoteOnly.

@Test
void testRemoteOnly() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), getMetadata());
    PlanRemotePojections rule = new PlanRemotePojections(getFunctionAndTypeManager());
    List<ProjectionContext> rewritten = rule.planRemoteAssignments(Assignments.builder().put(planBuilder.variable("a"), planBuilder.rowExpression("unittest.memory.remote_foo()")).put(planBuilder.variable("b"), planBuilder.rowExpression("unittest.memory.remote_foo(unittest.memory.remote_foo())")).build(), new PlanVariableAllocator(planBuilder.getTypes().allVariables()));
    assertEquals(rewritten.size(), 2);
    assertEquals(rewritten.get(1).getProjections().size(), 2);
}
Also used : ProjectionContext(com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 37 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestPlanRemoteProjections method testSpecialForm.

@Test
void testSpecialForm() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), getMetadata());
    planBuilder.variable("x", INTEGER);
    planBuilder.variable("y", INTEGER);
    PlanRemotePojections rule = new PlanRemotePojections(getFunctionAndTypeManager());
    List<ProjectionContext> rewritten = rule.planRemoteAssignments(Assignments.builder().put(planBuilder.variable("a"), planBuilder.rowExpression("unittest.memory.remote_foo(x, y + unittest.memory.remote_foo(x))")).put(planBuilder.variable("b"), planBuilder.rowExpression("x IS NULL OR y IS NULL")).put(planBuilder.variable("c"), planBuilder.rowExpression("IF(abs(unittest.memory.remote_foo()) > 0, x, y)")).put(planBuilder.variable("d"), planBuilder.rowExpression("unittest.memory.remote_foo(x + y, abs(x))")).put(planBuilder.variable("e"), planBuilder.rowExpression("TRUE OR FALSE")).build(), new PlanVariableAllocator(planBuilder.getTypes().allVariables()));
    assertEquals(rewritten.size(), 4);
    assertEquals(rewritten.get(3).getProjections().size(), 5);
}
Also used : ProjectionContext(com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 38 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder 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")))));
}
Also used : AggregationNode(com.facebook.presto.spi.plan.AggregationNode) PlanMatchPattern.filter(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.filter) BooleanType(com.facebook.presto.common.type.BooleanType) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) AGGREGATION_IF_TO_FILTER_REWRITE_STRATEGY(com.facebook.presto.SystemSessionProperties.AGGREGATION_IF_TO_FILTER_REWRITE_STRATEGY) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) Function(java.util.function.Function) ImmutableList(com.google.common.collect.ImmutableList) Symbol(com.facebook.presto.sql.planner.Symbol) PlanBuilder.assignment(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.assignment) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) ArrayType(com.facebook.presto.common.type.ArrayType) PlanMatchPattern.expression(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.functionCall(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.functionCall) PlanMatchPattern.aggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanMatchPattern.globalAggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.globalAggregation) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) PlanNode(com.facebook.presto.spi.plan.PlanNode) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ExpressionMatcher(com.facebook.presto.sql.planner.assertions.ExpressionMatcher) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) ExpressionMatcher(com.facebook.presto.sql.planner.assertions.ExpressionMatcher) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Symbol(com.facebook.presto.sql.planner.Symbol) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 39 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestCardinalityExtractorPlanVisitor method testLimitOnTopOfValues.

@Test
public void testLimitOnTopOfValues() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, 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));
}
Also used : PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 40 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class StatsCalculatorTester method assertStatsFor.

public StatsCalculatorAssertion assertStatsFor(Function<PlanBuilder, PlanNode> planProvider) {
    PlanBuilder planBuilder = new PlanBuilder(session, new PlanNodeIdAllocator(), metadata);
    PlanNode planNode = planProvider.apply(planBuilder);
    return new StatsCalculatorAssertion(statsCalculator, session, planNode, planBuilder.getTypes());
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Aggregations

PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)70 Test (org.testng.annotations.Test)56 PlanNode (com.facebook.presto.spi.plan.PlanNode)41 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)31 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)25 ImmutableList (com.google.common.collect.ImmutableList)23 ImmutableMap (com.google.common.collect.ImmutableMap)23 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)21 TopNNode (com.facebook.presto.spi.plan.TopNNode)20 Map (java.util.Map)19 Function (java.util.function.Function)19 Assert.assertEquals (org.testng.Assert.assertEquals)19 Ordering (com.facebook.presto.spi.plan.Ordering)18 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)18 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)18 Optional (java.util.Optional)18 BiConsumer (java.util.function.BiConsumer)18 Collectors (java.util.stream.Collectors)18 PinotColumnHandle (com.facebook.presto.pinot.PinotColumnHandle)16 SortOrder (com.facebook.presto.common.block.SortOrder)15