Search in sources :

Example 6 with TopNNode

use of io.prestosql.spi.plan.TopNNode 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)

Aggregations

TopNNode (io.prestosql.spi.plan.TopNNode)6 PlanNode (io.prestosql.spi.plan.PlanNode)3 ProjectNode (io.prestosql.spi.plan.ProjectNode)2 Test (org.testng.annotations.Test)2 Iterables (com.google.common.collect.Iterables)1 Session (io.prestosql.Session)1 Pattern (io.prestosql.matching.Pattern)1 SortOrder (io.prestosql.spi.block.SortOrder)1 AggregationNode (io.prestosql.spi.plan.AggregationNode)1 FilterNode (io.prestosql.spi.plan.FilterNode)1 JoinNode (io.prestosql.spi.plan.JoinNode)1 OrderingScheme (io.prestosql.spi.plan.OrderingScheme)1 Symbol (io.prestosql.spi.plan.Symbol)1 TableScanNode (io.prestosql.spi.plan.TableScanNode)1 CallExpression (io.prestosql.spi.relation.CallExpression)1 RowExpression (io.prestosql.spi.relation.RowExpression)1 LogicalPlanner (io.prestosql.sql.planner.LogicalPlanner)1 Plan (io.prestosql.sql.planner.Plan)1 TypeProvider (io.prestosql.sql.planner.TypeProvider)1 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)1