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);
}
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");
}
}
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))))));
}
Aggregations