Repository: drill Updated Branches: refs/heads/master b23e837bd -> 22539c8b3
DRILL-3574: For the empty Over-Clause, make DrillDistributionTrait to be as SINGLETON Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/22539c8b Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/22539c8b Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/22539c8b Branch: refs/heads/master Commit: 22539c8b381db1ca6813be4f39e6c3c4c5cb63af Parents: b23e837 Author: Hsuan-Yi Chu <[email protected]> Authored: Sun Aug 9 22:31:25 2015 -0700 Committer: Aman Sinha <[email protected]> Committed: Tue Aug 11 16:05:28 2015 -0700 ---------------------------------------------------------------------- .../physical/DrillDistributionTrait.java | 4 ++- .../exec/planner/physical/WindowPrule.java | 12 +++++++- .../apache/drill/exec/TestWindowFunctions.java | 32 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/22539c8b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/DrillDistributionTrait.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/DrillDistributionTrait.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/DrillDistributionTrait.java index c1e241d..b0e8940 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/DrillDistributionTrait.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/DrillDistributionTrait.java @@ -44,7 +44,9 @@ public class DrillDistributionTrait implements RelTrait { } public DrillDistributionTrait(DistributionType type, ImmutableList<DistributionField> fields) { - assert (type == DistributionType.HASH_DISTRIBUTED || type == DistributionType.RANGE_DISTRIBUTED); + assert (type == DistributionType.HASH_DISTRIBUTED + || type == DistributionType.RANGE_DISTRIBUTED + || type == DistributionType.SINGLETON); this.type = type; this.fields = fields; } http://git-wip-us.apache.org/repos/asf/drill/blob/22539c8b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrule.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrule.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrule.java index 034fd47..bcd9bcc 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrule.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrule.java @@ -42,6 +42,7 @@ import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.rel.type.RelRecordType; import org.apache.calcite.sql.SqlAggFunction; +import java.util.ArrayList; import java.util.List; public class WindowPrule extends Prule { @@ -64,7 +65,16 @@ public class WindowPrule extends Prule { for (final Ord<Window.Group> w : Ord.zip(window.groups)) { Window.Group windowBase = w.getValue(); RelTraitSet traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL); - if (windowBase.keys.size() > 0) { + + // For empty Over-Clause + if(windowBase.keys.isEmpty() + && windowBase.orderKeys.getFieldCollations().isEmpty()) { + DrillDistributionTrait distEmptyKeys = + new DrillDistributionTrait(DrillDistributionTrait.DistributionType.SINGLETON, + ImmutableList.copyOf(new ArrayList<DistributionField>())); + + traits = traits.plus(distEmptyKeys); + } else if (windowBase.keys.size() > 0) { DrillDistributionTrait distOnAllKeys = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionFields(windowBase))); http://git-wip-us.apache.org/repos/asf/drill/blob/22539c8b/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java index ce5a477..9e09106 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java @@ -23,6 +23,8 @@ import org.apache.drill.common.util.FileUtils; import org.apache.drill.common.util.TestTools; import org.apache.drill.exec.work.foreman.SqlUnsupportedException; import org.apache.drill.exec.work.foreman.UnsupportedFunctionException; +import org.apache.drill.PlanTestBase; + import org.junit.Test; public class TestWindowFunctions extends BaseTestQuery { @@ -450,4 +452,34 @@ public class TestWindowFunctions extends BaseTestQuery { .build() .run(); } + + @Test // see DRILL-3574 + public void testWithAndWithoutPartitions() throws Exception { + String root = FileUtils.getResourceAsFile("/store/text/data/t.json").toURI().toString(); + String query = String.format("select sum(a1) over(partition by b1, c1) as s1, sum(a1) over() as s2 \n" + + "from dfs_test.`%s` \n" + + "order by a1", root); + test("alter session set `planner.slice_target` = 1"); + + // Validate the plan + final String[] expectedPlan = {"Window\\(window#0=\\[window\\(partition \\{\\}.*\n" + + ".*UnionExchange"}; + PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, new String[]{}); + testBuilder() + .sqlQuery(query) + .unOrdered() + .baselineColumns("s1", "s2") + .baselineValues(0l, 50l) + .baselineValues(0l, 50l) + .baselineValues(0l, 50l) + .baselineValues(0l, 50l) + .baselineValues(0l, 50l) + .baselineValues(10l, 50l) + .baselineValues(10l, 50l) + .baselineValues(10l, 50l) + .baselineValues(20l, 50l) + .baselineValues(20l, 50l) + .build() + .run(); + } } \ No newline at end of file
