Search in sources :

Example 1 with OPTIMIZED_AND_VALIDATED

use of io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED in project trino by trinodb.

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", 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() == TopNNode.Step.PARTIAL).count();
    assertEquals(numberOfpartialTopN, 2, "There should be exactly two partial TopN nodes");
    assertPlanIsFullyDistributed(plan);
}
Also used : Iterables(com.google.common.collect.Iterables) PlanNodeSearcher.searchFrom(io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom) TopNNode(io.trino.sql.planner.plan.TopNNode) OPTIMIZED_AND_VALIDATED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) PlanNode(io.trino.sql.planner.plan.PlanNode) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GATHER(io.trino.sql.planner.plan.ExchangeNode.Type.GATHER) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) Map(java.util.Map) AggregationNode(io.trino.sql.planner.plan.AggregationNode) REPARTITION(io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION) Assert.assertTrue(org.testng.Assert.assertTrue) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) Plan(io.trino.sql.planner.Plan) JoinNode(io.trino.sql.planner.plan.JoinNode) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) Assert.assertFalse(org.testng.Assert.assertFalse) PlanNode(io.trino.sql.planner.plan.PlanNode) Plan(io.trino.sql.planner.Plan) TopNNode(io.trino.sql.planner.plan.TopNNode) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Aggregations

Iterables (com.google.common.collect.Iterables)1 OPTIMIZED_AND_VALIDATED (io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED)1 Plan (io.trino.sql.planner.Plan)1 BasePlanTest (io.trino.sql.planner.assertions.BasePlanTest)1 PlanNodeSearcher.searchFrom (io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom)1 AggregationNode (io.trino.sql.planner.plan.AggregationNode)1 ExchangeNode (io.trino.sql.planner.plan.ExchangeNode)1 REMOTE (io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE)1 GATHER (io.trino.sql.planner.plan.ExchangeNode.Type.GATHER)1 REPARTITION (io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION)1 JoinNode (io.trino.sql.planner.plan.JoinNode)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1 TopNNode (io.trino.sql.planner.plan.TopNNode)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 Assert.assertEquals (org.testng.Assert.assertEquals)1 Assert.assertFalse (org.testng.Assert.assertFalse)1 Assert.assertTrue (org.testng.Assert.assertTrue)1 Test (org.testng.annotations.Test)1