Search in sources :

Example 11 with ExchangeNode

use of io.prestosql.sql.planner.plan.ExchangeNode in project hetu-core by openlookeng.

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 : BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) Iterables(com.google.common.collect.Iterables) Assert.assertEquals(org.testng.Assert.assertEquals) Plan(io.prestosql.sql.planner.Plan) Test(org.testng.annotations.Test) PlanNode(io.prestosql.spi.plan.PlanNode) LogicalPlanner(io.prestosql.sql.planner.LogicalPlanner) AggregationNode(io.prestosql.spi.plan.AggregationNode) PlanNodeSearcher.searchFrom(io.prestosql.sql.planner.optimizations.PlanNodeSearcher.searchFrom) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GATHER(io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER) TopNNode(io.prestosql.spi.plan.TopNNode) Map(java.util.Map) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) Assert.assertTrue(org.testng.Assert.assertTrue) Assert.assertFalse(org.testng.Assert.assertFalse) JoinNode(io.prestosql.spi.plan.JoinNode) PlanNode(io.prestosql.spi.plan.PlanNode) Plan(io.prestosql.sql.planner.Plan) TopNNode(io.prestosql.spi.plan.TopNNode) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 12 with ExchangeNode

use of io.prestosql.sql.planner.plan.ExchangeNode in project hetu-core by openlookeng.

the class TestUnion method assertAtMostOneAggregationBetweenRemoteExchanges.

private static void assertAtMostOneAggregationBetweenRemoteExchanges(Plan plan) {
    List<PlanNode> fragments = searchFrom(plan.getRoot()).where(TestUnion::isRemoteExchange).findAll().stream().flatMap(exchangeNode -> exchangeNode.getSources().stream()).collect(toList());
    for (PlanNode fragment : fragments) {
        List<PlanNode> aggregations = searchFrom(fragment).where(AggregationNode.class::isInstance).recurseOnlyWhen(TestUnion::isNotRemoteExchange).findAll();
        assertFalse(aggregations.size() > 1, "More than a single AggregationNode between remote exchanges");
    }
}
Also used : BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) Iterables(com.google.common.collect.Iterables) Assert.assertEquals(org.testng.Assert.assertEquals) Plan(io.prestosql.sql.planner.Plan) Test(org.testng.annotations.Test) PlanNode(io.prestosql.spi.plan.PlanNode) LogicalPlanner(io.prestosql.sql.planner.LogicalPlanner) AggregationNode(io.prestosql.spi.plan.AggregationNode) PlanNodeSearcher.searchFrom(io.prestosql.sql.planner.optimizations.PlanNodeSearcher.searchFrom) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GATHER(io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER) TopNNode(io.prestosql.spi.plan.TopNNode) Map(java.util.Map) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) Assert.assertTrue(org.testng.Assert.assertTrue) Assert.assertFalse(org.testng.Assert.assertFalse) JoinNode(io.prestosql.spi.plan.JoinNode) PlanNode(io.prestosql.spi.plan.PlanNode) AggregationNode(io.prestosql.spi.plan.AggregationNode)

Example 13 with ExchangeNode

use of io.prestosql.sql.planner.plan.ExchangeNode in project hetu-core by openlookeng.

the class TestLogicalPlanner method testUsesDistributedJoinIfNaturallyPartitionedOnProbeSymbols.

@Test
public void testUsesDistributedJoinIfNaturallyPartitionedOnProbeSymbols() {
    Session broadcastJoin = Session.builder(this.getQueryRunner().getDefaultSession()).setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.BROADCAST.name()).setSystemProperty(FORCE_SINGLE_NODE_OUTPUT, Boolean.toString(false)).setSystemProperty(OPTIMIZE_HASH_GENERATION, Boolean.toString(false)).build();
    // replicated join with naturally partitioned and distributed probe side is rewritten to partitioned join
    assertPlanWithSession("SELECT r1.regionkey FROM (SELECT regionkey FROM region GROUP BY regionkey) r1, region r2 WHERE r2.regionkey = r1.regionkey", broadcastJoin, false, anyTree(join(INNER, ImmutableList.of(equiJoinClause("LEFT_REGIONKEY", "RIGHT_REGIONKEY")), Optional.empty(), Optional.of(PARTITIONED), // the only remote exchange in probe side should be below aggregation
    aggregation(ImmutableMap.of(), anyTree(exchange(REMOTE, REPARTITION, anyTree(tableScan("region", ImmutableMap.of("LEFT_REGIONKEY", "regionkey")))))), anyTree(exchange(REMOTE, REPARTITION, tableScan("region", ImmutableMap.of("RIGHT_REGIONKEY", "regionkey")))))), // make sure there are only two remote exchanges (one in probe and one in build side)
    plan -> assertEquals(countOfMatchingNodes(plan, node -> node instanceof ExchangeNode && ((ExchangeNode) node).getScope() == REMOTE), 2));
    // replicated join is preserved if probe side is single node
    assertPlanWithSession("SELECT * FROM (SELECT * FROM (VALUES 1) t(a)) t, region r WHERE r.regionkey = t.a", broadcastJoin, false, anyTree(node(JoinNode.class, node(ValuesNode.class), anyTree(exchange(REMOTE, GATHER, anyTree(node(TableScanNode.class)))))));
    // replicated join is preserved if there are no equality criteria
    assertPlanWithSession("SELECT * FROM (SELECT regionkey FROM region GROUP BY regionkey) r1, region r2 WHERE r2.regionkey > r1.regionkey", broadcastJoin, false, anyTree(join(INNER, ImmutableList.of(), Optional.empty(), Optional.of(REPLICATED), anyTree(node(TableScanNode.class)), anyTree(exchange(REMOTE, REPLICATE, node(TableScanNode.class))))));
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) Session(io.prestosql.Session) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Aggregations

ExchangeNode (io.prestosql.sql.planner.plan.ExchangeNode)13 AggregationNode (io.prestosql.spi.plan.AggregationNode)7 PlanNode (io.prestosql.spi.plan.PlanNode)6 Symbol (io.prestosql.spi.plan.Symbol)6 Test (org.testng.annotations.Test)6 JoinNode (io.prestosql.spi.plan.JoinNode)5 ProjectNode (io.prestosql.spi.plan.ProjectNode)4 TableScanNode (io.prestosql.spi.plan.TableScanNode)4 List (java.util.List)4 Map (java.util.Map)4 ImmutableList (com.google.common.collect.ImmutableList)3 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)3 Iterables (com.google.common.collect.Iterables)2 Session (io.prestosql.Session)2 Assignments (io.prestosql.spi.plan.Assignments)2 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)2 TopNNode (io.prestosql.spi.plan.TopNNode)2 Type (io.prestosql.spi.type.Type)2 LogicalPlanner (io.prestosql.sql.planner.LogicalPlanner)2 PartitioningScheme (io.prestosql.sql.planner.PartitioningScheme)2