Add planner tests for distributed sort
@@ -47,6 +47,7 @@ import java.util.function.Consumer;
import java.util.function.Predicate;
import static com.facebook.presto.SystemSessionProperties.DISTRIBUTED_JOIN;
+import static com.facebook.presto.SystemSessionProperties.DISTRIBUTED_SORT;
import static com.facebook.presto.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT;
import static com.facebook.presto.SystemSessionProperties.OPTIMIZE_HASH_GENERATION;
import static com.facebook.presto.spi.predicate.Domain.singleValue;
@@ -70,11 +71,13 @@ import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.semiJoin;
+import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.sort;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.strictTableScan;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values;
import static com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher.searchFrom;
import static com.facebook.presto.sql.planner.plan.AggregationNode.Step.SINGLE;
+import static com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.LOCAL;
import static com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.REMOTE;
import static com.facebook.presto.sql.planner.plan.ExchangeNode.Type.GATHER;
import static com.facebook.presto.sql.planner.plan.ExchangeNode.Type.REPARTITION;
@@ -83,6 +86,8 @@ import static com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PAR
import static com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED;
import static com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER;
import static com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT;
+import static com.facebook.presto.sql.tree.SortItem.NullOrdering.LAST;
+import static com.facebook.presto.sql.tree.SortItem.Ordering.DESCENDING;
import static com.facebook.presto.tests.QueryTemplate.queryTemplate;
import static com.facebook.presto.util.MorePredicates.isInstanceOfAny;
import static io.airlift.slice.Slices.utf8Slice;
@@ -678,4 +683,31 @@ public class TestLogicalPlanner
exchange(REMOTE, REPLICATE,
node(TableScanNode.class))))));
}
+
+ @Test
+ public void testDistributedSort()
+ {
+ ImmutableList<PlanMatchPattern.Ordering> orderBy = ImmutableList.of(sort("ORDERKEY", DESCENDING, LAST));
+ assertDistributedPlan(
+ "SELECT orderkey FROM orders ORDER BY orderkey DESC",
+ output(
+ exchange(REMOTE, GATHER, orderBy,
+ exchange(LOCAL, GATHER, orderBy,
+ sort(orderBy,
+ exchange(REMOTE, REPARTITION,
+ tableScan("orders", ImmutableMap.of(
+ "ORDERKEY", "orderkey"))))))));
+
+ assertDistributedPlan(
+ "SELECT orderkey FROM orders ORDER BY orderkey DESC",
+ Session.builder(this.getQueryRunner().getDefaultSession())
+ .setSystemProperty(DISTRIBUTED_SORT, Boolean.toString(false))
+ .build(),
+ output(
+ sort(orderBy,
+ exchange(LOCAL, GATHER,
+ exchange(REMOTE, GATHER,
+ tableScan("orders", ImmutableMap.of(
+ "ORDERKEY", "orderkey")))))));
+ }
}
