Search in sources :

Example 16 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestRemoveUnsupportedDynamicFilters method testNestedDynamicFilterDisjunctionRewrite.

@Test
public void testNestedDynamicFilterDisjunctionRewrite() {
    PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, ordersTableScanNode, builder.filter(logicalRowExpressions.combineConjuncts(logicalRowExpressions.combineDisjuncts(builder.rowExpression("LINEITEM_OK IS NULL"), createDynamicFilterExpression("DF", lineitemOrderKeyVariable, metadata.getFunctionAndTypeManager())), logicalRowExpressions.combineDisjuncts(builder.rowExpression("LINEITEM_OK IS NOT NULL"), createDynamicFilterExpression("DF", lineitemOrderKeyVariable, metadata.getFunctionAndTypeManager()))), lineitemTableScanNode), ImmutableList.of(new JoinNode.EquiJoinClause(ordersOrderKeyVariable, lineitemOrderKeyVariable)), ImmutableList.of(ordersOrderKeyVariable), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()));
    assertPlan(removeUnsupportedDynamicFilters(root), output(join(INNER, ImmutableList.of(equiJoinClause("ORDERS_OK", "LINEITEM_OK")), tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey")), tableScan("lineitem", ImmutableMap.of("LINEITEM_OK", "orderkey")))));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 17 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestUnion method testUnionUnderTopN.

@Test
public void testUnionUnderTopN() {
    Plan plan = plan("SELECT * FROM (" + "   SELECT regionkey FROM nation " + "   UNION ALL " + "   SELECT nationkey FROM nation" + ") t(a) " + "ORDER BY a LIMIT 1", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
    List<PlanNode> remotes = searchFrom(plan.getRoot()).where(TestUnion::isRemoteExchange).findAll();
    assertEquals(remotes.size(), 1, "There should be exactly one RemoteExchange");
    assertEquals(((ExchangeNode) Iterables.getOnlyElement(remotes)).getType(), GATHER);
    int numberOfpartialTopN = searchFrom(plan.getRoot()).where(planNode -> planNode instanceof TopNNode && ((TopNNode) planNode).getStep().equals(TopNNode.Step.PARTIAL)).count();
    assertEquals(numberOfpartialTopN, 2, "There should be exactly two partial TopN nodes");
    assertPlanIsFullyDistributed(plan);
}
Also used : JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Iterables(com.google.common.collect.Iterables) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) GATHER(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.GATHER) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) REPARTITION(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.REPARTITION) TopNNode(com.facebook.presto.spi.plan.TopNNode) Map(java.util.Map) Assert.assertTrue(org.testng.Assert.assertTrue) Plan(com.facebook.presto.sql.planner.Plan) Assert.assertFalse(org.testng.Assert.assertFalse) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) PlanNodeSearcher.searchFrom(com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher.searchFrom) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) Plan(com.facebook.presto.sql.planner.Plan) TopNNode(com.facebook.presto.spi.plan.TopNNode) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 18 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestUnion method testUnionOverSingleNodeAggregationAndUnion.

@Test
public void testUnionOverSingleNodeAggregationAndUnion() {
    Plan plan = plan("SELECT count(*) FROM (" + "SELECT 1 FROM nation GROUP BY regionkey " + "UNION ALL (" + "   SELECT 1 FROM nation " + "   UNION ALL " + "   SELECT 1 FROM nation))", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
    List<PlanNode> remotes = searchFrom(plan.getRoot()).where(TestUnion::isRemoteExchange).findAll();
    assertEquals(remotes.size(), 2, "There should be exactly two RemoteExchanges");
    assertEquals(((ExchangeNode) remotes.get(0)).getType(), GATHER);
    assertEquals(((ExchangeNode) remotes.get(1)).getType(), REPARTITION);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) Plan(com.facebook.presto.sql.planner.Plan) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 19 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestUnion method testSimpleUnion.

@Test
public void testSimpleUnion() {
    Plan plan = plan("SELECT suppkey FROM supplier UNION ALL SELECT nationkey FROM nation", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
    List<PlanNode> remotes = searchFrom(plan.getRoot()).where(TestUnion::isRemoteExchange).findAll();
    assertEquals(remotes.size(), 1, "There should be exactly one RemoteExchange");
    assertEquals(((ExchangeNode) Iterables.getOnlyElement(remotes)).getType(), GATHER);
    assertPlanIsFullyDistributed(plan);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) Plan(com.facebook.presto.sql.planner.Plan) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 20 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestDynamicFiltersChecker method testDynamicFilterConsumedOnBuildSide.

@Test(expectedExceptions = VerifyException.class, expectedExceptionsMessageRegExp = "Dynamic filters \\[DF\\] present in join were consumed by its build side. consumedBuildSide \\[DF\\], currentJoinDynamicFilters \\[DF\\]")
public void testDynamicFilterConsumedOnBuildSide() {
    PlanNode root = builder.join(INNER, builder.filter(createDynamicFilterExpression("DF", ordersOrderKeyVariable, metadata.getFunctionAndTypeManager()), ordersTableScanNode), builder.filter(createDynamicFilterExpression("DF", ordersOrderKeyVariable, metadata.getFunctionAndTypeManager()), lineitemTableScanNode), ImmutableList.of(new JoinNode.EquiJoinClause(ordersOrderKeyVariable, lineitemOrderKeyVariable)), ImmutableList.of(ordersOrderKeyVariable), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of("DF", lineitemOrderKeyVariable));
    validatePlan(root);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Aggregations

PlanNode (com.facebook.presto.spi.plan.PlanNode)228 Test (org.testng.annotations.Test)114 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)94 ImmutableList (com.google.common.collect.ImmutableList)56 RowExpression (com.facebook.presto.spi.relation.RowExpression)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)42 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)41 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)40 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)40 Map (java.util.Map)39 Optional (java.util.Optional)38 List (java.util.List)36 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)35 Set (java.util.Set)30 Assert.assertEquals (org.testng.Assert.assertEquals)23 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)22 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)20 Function (java.util.function.Function)20 Metadata (com.facebook.presto.metadata.Metadata)19