Return-Path: X-Original-To: apmail-drill-commits-archive@www.apache.org Delivered-To: apmail-drill-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5CD3217E21 for ; Fri, 12 Jun 2015 05:12:16 +0000 (UTC) Received: (qmail 2231 invoked by uid 500); 12 Jun 2015 05:12:16 -0000 Delivered-To: apmail-drill-commits-archive@drill.apache.org Received: (qmail 2195 invoked by uid 500); 12 Jun 2015 05:12:16 -0000 Mailing-List: contact commits-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: commits@drill.apache.org Delivered-To: mailing list commits@drill.apache.org Received: (qmail 2186 invoked by uid 99); 12 Jun 2015 05:12:16 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jun 2015 05:12:16 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2D2C3DFFD5; Fri, 12 Jun 2015 05:12:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: amansinha@apache.org To: commits@drill.apache.org Message-Id: <47dd48027d8548128c00fb465fd9ee98@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: drill git commit: DRILL-1862: Create window function required distribution and collation traits conditionally. Date: Fri, 12 Jun 2015 05:12:16 +0000 (UTC) Repository: drill Updated Branches: refs/heads/master 3bccec911 -> fb1d3f384 DRILL-1862: Create window function required distribution and collation traits conditionally. Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/fb1d3f38 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/fb1d3f38 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/fb1d3f38 Branch: refs/heads/master Commit: fb1d3f384e6c79a540e34e70f8268feb689208ee Parents: 3bccec9 Author: Aman Sinha Authored: Tue Jun 9 12:48:48 2015 -0700 Committer: Aman Sinha Committed: Thu Jun 11 17:51:31 2015 -0700 ---------------------------------------------------------------------- .../exec/planner/physical/WindowPrule.java | 28 ++++++++++++++---- .../physical/impl/window/TestWindowFrame.java | 31 ++++++++++---------- 2 files changed, 37 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/fb1d3f38/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 db9218a..f7728c8 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 @@ -22,7 +22,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.sun.java.swing.plaf.windows.resources.windows; + import org.apache.calcite.linq4j.Ord; import org.apache.calcite.rel.core.Window; import org.apache.calcite.util.BitSets; @@ -58,14 +58,25 @@ public class WindowPrule extends RelOptRule { // TODO: Order window based on existing partition by //input.getTraitSet().subsumes() + boolean partitionby = false; for (final Ord w : Ord.zip(window.groups)) { Window.Group windowBase = w.getValue(); - DrillDistributionTrait distOnAllKeys = - new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, - ImmutableList.copyOf(getDistributionFields(windowBase))); + RelTraitSet traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL); + if (windowBase.keys.size() > 0) { + DrillDistributionTrait distOnAllKeys = + new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, + ImmutableList.copyOf(getDistributionFields(windowBase))); + + partitionby = true; + traits = traits.plus(distOnAllKeys); + } + + // Add collation trait if either partition-by or order-by is specified. + if (partitionby || windowBase.orderKeys.getFieldCollations().size() > 0) { + RelCollation collation = getCollation(windowBase); + traits = traits.plus(collation); + } - RelCollation collation = getCollation(windowBase); - RelTraitSet traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation).plus(distOnAllKeys); final RelNode convertedInput = convert(input, traits); List newRowFields = Lists.newArrayList(); @@ -115,6 +126,11 @@ public class WindowPrule extends RelOptRule { call.transformTo(input); } + /** + * Create a RelCollation that has partition-by as the leading keys followed by order-by keys + * @param window The window specification + * @return a RelCollation with {partition-by keys, order-by keys} + */ private RelCollation getCollation(Window.Group window) { List fields = Lists.newArrayList(); for (int group : BitSets.toIter(window.keys)) { http://git-wip-us.apache.org/repos/asf/drill/blob/fb1d3f38/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/window/TestWindowFrame.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/window/TestWindowFrame.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/window/TestWindowFrame.java index 15fefa5..4295002 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/window/TestWindowFrame.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/window/TestWindowFrame.java @@ -17,6 +17,8 @@ ******************************************************************************/ package org.apache.drill.exec.physical.impl.window; +import java.util.Properties; + import org.apache.drill.BaseTestQuery; import org.apache.drill.DrillTestWrapper; import org.apache.drill.common.config.DrillConfig; @@ -25,8 +27,6 @@ import org.apache.drill.exec.ExecConstants; import org.junit.BeforeClass; import org.junit.Test; -import java.util.Properties; - public class TestWindowFrame extends BaseTestQuery { private static final String TEST_RES_PATH = TestTools.getWorkingPath() + "/src/test/resources"; @@ -63,15 +63,10 @@ public class TestWindowFrame extends BaseTestQuery { } private void runTest(final String tableName, final boolean withOrderBy) throws Exception { - runSQL(String.format("alter session set `%s`= true", ExecConstants.ENABLE_WINDOW_FUNCTIONS)); - try { - DrillTestWrapper testWrapper = withOrderBy ? - buildWindowWithOrderByQuery(tableName) : buildWindowQuery(tableName); - testWrapper.run(); - } finally { - runSQL(String.format("alter session set `%s`= false", ExecConstants.ENABLE_WINDOW_FUNCTIONS)); - } + DrillTestWrapper testWrapper = withOrderBy ? + buildWindowWithOrderByQuery(tableName) : buildWindowQuery(tableName); + testWrapper.run(); } /** @@ -170,13 +165,17 @@ public class TestWindowFrame extends BaseTestQuery { @Test // DRILL-3218 public void testMaxVarChar() throws Exception { - runSQL(String.format("alter session set `%s`= true", ExecConstants.ENABLE_WINDOW_FUNCTIONS)); + test("select max(cast(columns[2] as char(2))) over(partition by cast(columns[2] as char(2)) order by cast(columns[0] as int)) from dfs_test.`%s/window/allData.csv`", TEST_RES_PATH); + } - try { - test("select max(cast(columns[2] as char(2))) over(partition by cast(columns[2] as char(2)) order by cast(columns[0] as int)) from dfs_test.`%s/window/allData.csv`", TEST_RES_PATH); - } finally { - runSQL(String.format("alter session set `%s`= false", ExecConstants.ENABLE_WINDOW_FUNCTIONS)); - } + @Test // DRILL-1862 + public void testEmptyPartitionBy() throws Exception { + test("SELECT employee_id, position_id, salary, SUM(salary) OVER(ORDER BY position_id) FROM cp.`employee.json` LIMIT 10"); + } + @Test // DRILL-3172 + public void testEmptyOverClause() throws Exception { + test("SELECT employee_id, position_id, salary, SUM(salary) OVER() FROM cp.`employee.json` LIMIT 10"); } + }