You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by jn...@apache.org on 2015/09/11 07:20:11 UTC

[1/6] drill git commit: DRILL-3580: Add test case and bump calcite version to 1.4.0-drill-r2

Repository: drill
Updated Branches:
  refs/heads/master fdb6b4fec -> b525692e0


DRILL-3580: Add test case and bump calcite version to 1.4.0-drill-r2

Fix is in CALCITE-841


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/9a313933
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/9a313933
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/9a313933

Branch: refs/heads/master
Commit: 9a313933074ee95f53c15a511c41524f723c0ccf
Parents: fdb6b4f
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Tue Sep 8 10:42:51 2015 -0700
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Thu Sep 10 17:45:06 2015 -0700

----------------------------------------------------------------------
 .../apache/drill/exec/TestWindowFunctions.java  | 28 ++++++++++++++++++++
 pom.xml                                         |  2 +-
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/9a313933/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 29b702c..dbbc777 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
@@ -450,4 +450,32 @@ public class TestWindowFunctions extends BaseTestQuery {
         .build()
         .run();
   }
+
+  @Test // DRILL-3580
+  public void testExpressionInWindowFunction() throws Exception {
+    String root = FileUtils.getResourceAsFile("/store/text/data/t.json").toURI().toString();
+    String query = String.format("select a1, b1, sum(b1) over (partition by a1) as c1, sum(a1 + b1) over (partition by a1) as c2\n" +
+        "from dfs_test.`%s`", root);
+
+    // Validate the plan
+    final String[] expectedPlan = {"Window\\(window#0=\\[window\\(partition \\{0\\} order by \\[\\].*\\[SUM\\(\\$1\\), SUM\\(\\$2\\)\\]"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, new String[]{});
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("a1", "b1", "c1", "c2")
+        .baselineValues(0l, 1l, 8l, 8l)
+        .baselineValues(0l, 1l, 8l, 8l)
+        .baselineValues(0l, 2l, 8l, 8l)
+        .baselineValues(0l, 2l, 8l, 8l)
+        .baselineValues(0l, 2l, 8l, 8l)
+        .baselineValues(10l, 3l, 21l, 71l)
+        .baselineValues(10l, 3l, 21l, 71l)
+        .baselineValues(10l, 5l, 21l, 71l)
+        .baselineValues(10l, 5l, 21l, 71l)
+        .baselineValues(10l, 5l, 21l, 71l)
+        .build()
+        .run();
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/9a313933/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 8d4b318..c17e612 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1226,7 +1226,7 @@
           <dependency>
             <groupId>org.apache.calcite</groupId>
             <artifactId>calcite-core</artifactId>
-            <version>1.4.0-drill-r0</version>
+            <version>1.4.0-drill-r2</version>
             <exclusions>
               <exclusion>
                 <groupId>org.jgrapht</groupId>


[5/6] drill git commit: DRILL-3755: In DrillSqlWorker, give UserException.validationError if ValidationException is thrown from Calcite

Posted by jn...@apache.org.
DRILL-3755: In DrillSqlWorker, give UserException.validationError if ValidationException is thrown from Calcite


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/1b333678
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/1b333678
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/1b333678

Branch: refs/heads/master
Commit: 1b333678f3a2b32b5d6bad4ddf3b1001e33b42f7
Parents: e29a153
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Mon Sep 7 16:47:18 2015 -0700
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Thu Sep 10 17:46:10 2015 -0700

----------------------------------------------------------------------
 .../drill/exec/planner/sql/DrillSqlWorker.java  | 10 ++++----
 .../apache/drill/exec/TestWindowFunctions.java  | 27 ++++++++++++--------
 2 files changed, 21 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/1b333678/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
index bc79cff..64a2e1c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
@@ -178,15 +178,15 @@ public class DrillSqlWorker {
       return handler.getPlan(sqlNode);
     } catch(ValidationException e) {
       String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
-      throw UserException.parseError(e)
-        .message(errorMessage)
-        .build(logger);
+      throw UserException.validationError(e)
+          .message(errorMessage)
+          .build(logger);
     } catch (AccessControlException e) {
       throw UserException.permissionError(e)
-        .build(logger);
+          .build(logger);
     } catch(SqlUnsupportedException e) {
       throw UserException.unsupportedError(e)
-        .build(logger);
+          .build(logger);
     } catch (IOException | RelConversionException e) {
       throw new QueryInputException("Failure handling SQL.", e);
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/1b333678/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 0efd55c..9a3bc7b 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
@@ -21,10 +21,12 @@ import org.apache.drill.BaseTestQuery;
 import org.apache.drill.common.exceptions.UserException;
 import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.common.util.TestTools;
+import org.apache.drill.exec.proto.UserBitShared;
 import org.apache.drill.exec.work.foreman.SqlUnsupportedException;
 import org.apache.drill.exec.work.foreman.UnsupportedFunctionException;
 import org.apache.drill.PlanTestBase;
 
+import org.apache.drill.test.UserExceptionMatcher;
 import org.junit.Test;
 
 public class TestWindowFunctions extends BaseTestQuery {
@@ -211,16 +213,18 @@ public class TestWindowFunctions extends BaseTestQuery {
 
   @Test // DRILL-3344
   public void testWindowGroupBy() throws Exception {
+    thrownException.expect(new UserExceptionMatcher(UserBitShared.DrillPBError.ErrorType.VALIDATION));
     String query = "explain plan for SELECT max(n_nationkey) OVER (), n_name as col2 \n" +
         "from cp.`tpch/nation.parquet` \n" +
         "group by n_name";
 
-    parseErrorHelper(query);
+    test(query);
   }
 
   @Test // DRILL-3346
   public void testWindowGroupByOnView() throws Exception {
     try {
+      thrownException.expect(new UserExceptionMatcher(UserBitShared.DrillPBError.ErrorType.VALIDATION));
       String createView = "create view testWindowGroupByOnView(a, b) as \n" +
           "select n_nationkey, n_name from cp.`tpch/nation.parquet`";
       String query = "explain plan for SELECT max(a) OVER (), b as col2 \n" +
@@ -229,7 +233,7 @@ public class TestWindowFunctions extends BaseTestQuery {
 
       test("use dfs_test.tmp");
       test(createView);
-      parseErrorHelper(query);
+      test(query);
     } finally {
       test("drop view testWindowGroupByOnView");
     }
@@ -402,15 +406,16 @@ public class TestWindowFunctions extends BaseTestQuery {
       PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
 
       testBuilder()
-        .sqlQuery(query)
-        .ordered()
-        .baselineColumns("cnt")
-        .optionSettingQueriesForTestQuery("alter session set `planner.slice_target` = 1")
-        .baselineValues(1l)
-        .baselineValues(4l)
-        .baselineValues(4l)
-        .baselineValues(4l)
-        .build().run();
+          .sqlQuery(query)
+          .ordered()
+          .baselineColumns("cnt")
+          .optionSettingQueriesForTestQuery("alter session set `planner.slice_target` = 1")
+          .baselineValues(1l)
+          .baselineValues(4l)
+          .baselineValues(4l)
+          .baselineValues(4l)
+          .build()
+          .run();
     } finally {
       test("alter session set `planner.slice_target` = " + ExecConstants.SLICE_TARGET_DEFAULT);
     }


[6/6] drill git commit: DRILL-3280, DRILL-3360, DRILL-3601, DRILL-3649: Add test cases

Posted by jn...@apache.org.
DRILL-3280, DRILL-3360, DRILL-3601, DRILL-3649: Add test cases

Fix is in CALCITE-820

Close apache/drill#152


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/b525692e
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/b525692e
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/b525692e

Branch: refs/heads/master
Commit: b525692e05c2a562a664093abd46bf68137b4a3b
Parents: 1b33367
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Wed Sep 9 16:21:54 2015 -0700
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Thu Sep 10 17:52:25 2015 -0700

----------------------------------------------------------------------
 .../apache/drill/exec/TestWindowFunctions.java  | 35 ++++++++++++++++++++
 1 file changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/b525692e/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 9a3bc7b..b60f188 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
@@ -211,6 +211,41 @@ public class TestWindowFunctions extends BaseTestQuery {
     }
   }
 
+  @Test // DRILL-3360
+  public void testWindowInWindow() throws Exception {
+    thrownException.expect(new UserExceptionMatcher(UserBitShared.DrillPBError.ErrorType.VALIDATION));
+    String query = "select rank() over(order by row_number() over(order by n_nationkey)) \n" +
+        "from cp.`tpch/nation.parquet`";
+
+    test(query);
+  }
+
+  @Test // DRILL-3280
+  public void testMissingOverWithWindowClause() throws Exception {
+    thrownException.expect(new UserExceptionMatcher(UserBitShared.DrillPBError.ErrorType.VALIDATION));
+    String query = "select rank(), cume_dist() over w \n" +
+        "from cp.`tpch/nation.parquet` \n" +
+        "window w as (partition by n_name order by n_nationkey)";
+
+    test(query);
+  }
+
+  @Test // DRILL-3601
+  public void testLeadMissingOver() throws Exception {
+    thrownException.expect(new UserExceptionMatcher(UserBitShared.DrillPBError.ErrorType.VALIDATION));
+    String query = "select lead(n_nationkey) from cp.`tpch/nation.parquet`";
+
+    test(query);
+  }
+
+  @Test // DRILL-3649
+  public void testMissingOverWithConstant() throws Exception {
+    thrownException.expect(new UserExceptionMatcher(UserBitShared.DrillPBError.ErrorType.VALIDATION));
+    String query = "select NTILE(1) from cp.`tpch/nation.parquet`";
+
+    test(query);
+  }
+
   @Test // DRILL-3344
   public void testWindowGroupBy() throws Exception {
     thrownException.expect(new UserExceptionMatcher(UserBitShared.DrillPBError.ErrorType.VALIDATION));


[4/6] drill git commit: DRILL-2190, DRILL-2313, DRILL-2318: Add test cases

Posted by jn...@apache.org.
DRILL-2190, DRILL-2313, DRILL-2318: Add test cases

Fixes are in CALCITE-634, CALCITE-613, CALCITE-662


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/e29a1530
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/e29a1530
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/e29a1530

Branch: refs/heads/master
Commit: e29a153076c04939e539c2862b5ef3ec8f96021c
Parents: 24bcca1
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Fri Sep 4 11:35:45 2015 -0700
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Thu Sep 10 17:46:03 2015 -0700

----------------------------------------------------------------------
 .../org/apache/drill/TestExampleQueries.java    | 69 ++++++++++++++++++++
 .../apache/drill/exec/sql/TestWithClause.java   | 22 +++++++
 2 files changed, 91 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/e29a1530/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
index d15cff2..58c7862 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
@@ -1121,4 +1121,73 @@ public class TestExampleQueries extends BaseTestQuery {
         .build()
         .run();
   }
+
+  @Test // see DRILL-2313
+  public void testDistinctOverAggFunctionWithGroupBy() throws Exception {
+    String query1 = "select distinct count(distinct n_nationkey) as col from cp.`tpch/nation.parquet` group by n_regionkey order by 1";
+    String query2 = "select distinct count(distinct n_nationkey) as col from cp.`tpch/nation.parquet` group by n_regionkey order by count(distinct n_nationkey)";
+    String query3 = "select distinct sum(n_nationkey) as col from cp.`tpch/nation.parquet` group by n_regionkey order by 1";
+    String query4 = "select distinct sum(n_nationkey) as col from cp.`tpch/nation.parquet` group by n_regionkey order by col";
+
+    testBuilder()
+        .sqlQuery(query1)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues((long) 5)
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(query2)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues((long) 5)
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(query3)
+        .ordered()
+        .baselineColumns("col")
+        .baselineValues((long) 47)
+        .baselineValues((long) 50)
+        .baselineValues((long) 58)
+        .baselineValues((long) 68)
+        .baselineValues((long) 77)
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(query4)
+        .ordered()
+        .baselineColumns("col")
+        .baselineValues((long) 47)
+        .baselineValues((long) 50)
+        .baselineValues((long) 58)
+        .baselineValues((long) 68)
+        .baselineValues((long) 77)
+        .build()
+        .run();
+  }
+
+  @Test // DRILL-2190
+  public void testDateImplicitCasting() throws Exception {
+    String query = "SELECT birth_date \n" +
+        "FROM cp.`employee.json` \n" +
+        "WHERE birth_date BETWEEN '1920-01-01' AND cast('1931-01-01' AS DATE) \n" +
+        "order by birth_date";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("birth_date")
+        .baselineValues("1920-04-17")
+        .baselineValues("1921-12-04")
+        .baselineValues("1922-08-10")
+        .baselineValues("1926-10-27")
+        .baselineValues("1928-03-20")
+        .baselineValues("1930-01-08")
+        .build()
+        .run();
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/e29a1530/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestWithClause.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestWithClause.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestWithClause.java
index 3a32045..ff04f8c 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestWithClause.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestWithClause.java
@@ -39,4 +39,26 @@ public class TestWithClause extends BaseTestQuery {
         "select x, y from alpha");
   }
 
+  @Test // DRILL-2318
+  public void withClauseOrderBy() throws Exception {
+    String query = "WITH x \n" +
+        "AS (SELECT n_nationkey a1 \n" +
+        "FROM  cp.`tpch/nation.parquet`) \n" +
+        "SELECT  x.a1 \n" +
+        "FROM  x \n" +
+        "ORDER BY x.a1 \n" +
+        "limit 5";
+
+    testBuilder()
+      .sqlQuery(query)
+      .ordered()
+      .baselineColumns("a1")
+      .baselineValues(0)
+      .baselineValues(1)
+      .baselineValues(2)
+      .baselineValues(3)
+      .baselineValues(4)
+      .build()
+      .run();
+  }
 }


[3/6] drill git commit: DRILL-3683: Add baseline and expected plan for TestWindowFunctions suite

Posted by jn...@apache.org.
DRILL-3683: Add baseline and expected plan for TestWindowFunctions suite


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/24bcca11
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/24bcca11
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/24bcca11

Branch: refs/heads/master
Commit: 24bcca11629dbd6302161cc36cb312595b2a1790
Parents: 27e4bac
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Fri Aug 21 17:11:49 2015 -0700
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Thu Sep 10 17:45:56 2015 -0700

----------------------------------------------------------------------
 .../apache/drill/exec/TestWindowFunctions.java  | 299 ++++++++++++++++++-
 1 file changed, 284 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/24bcca11/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 0ce82f5..0efd55c 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
@@ -38,19 +38,91 @@ public class TestWindowFunctions extends BaseTestQuery {
 
   @Test // DRILL-3196
   public void testSinglePartition() throws Exception {
-    final String query = "explain plan for select sum(a2) over(partition by a2), count(*) over(partition by a2) \n" +
+    final String query = "select sum(n_nationKey) over(partition by n_nationKey) as col1, count(*) over(partition by n_nationKey) as col2 \n" +
         "from cp.`tpch/nation.parquet`";
 
-    test(query);
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{0\\} order by \\[\\].*\\[SUM\\(\\$0\\), COUNT\\(\\)",
+        "Scan.*columns=\\[`n_nationKey`\\].*"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\].*"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col1", "col2")
+        .baselineValues(0l, 1l)
+        .baselineValues(1l, 1l)
+        .baselineValues(2l, 1l)
+        .baselineValues(3l, 1l)
+        .baselineValues(4l, 1l)
+        .baselineValues(5l, 1l)
+        .baselineValues(6l, 1l)
+        .baselineValues(7l, 1l)
+        .baselineValues(8l, 1l)
+        .baselineValues(9l, 1l)
+        .baselineValues(10l, 1l)
+        .baselineValues(11l, 1l)
+        .baselineValues(12l, 1l)
+        .baselineValues(13l, 1l)
+        .baselineValues(14l, 1l)
+        .baselineValues(15l, 1l)
+        .baselineValues(16l, 1l)
+        .baselineValues(17l, 1l)
+        .baselineValues(18l, 1l)
+        .baselineValues(19l, 1l)
+        .baselineValues(20l, 1l)
+        .baselineValues(21l, 1l)
+        .baselineValues(22l, 1l)
+        .baselineValues(23l, 1l)
+        .baselineValues(24l, 1l)
+        .build()
+        .run();
   }
 
   @Test // DRILL-3196
   public void testSinglePartitionDefinedInWindowList() throws Exception {
-    final String query = "explain plan for select sum(a2) over w \n" +
+    final String query = "select sum(n_nationKey) over w as col \n" +
         "from cp.`tpch/nation.parquet` \n" +
-        "window w as (partition by a2 order by a2)";
+        "window w as (partition by n_nationKey order by n_nationKey)";
+
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{0\\} order by \\[0\\].*SUM\\(\\$0\\)",
+        "Scan.*columns=\\[`n_nationKey`\\].*"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\].*"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
 
-    test(query);
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(0l)
+        .baselineValues(1l)
+        .baselineValues(2l)
+        .baselineValues(3l)
+        .baselineValues(4l)
+        .baselineValues(5l)
+        .baselineValues(6l)
+        .baselineValues(7l)
+        .baselineValues(8l)
+        .baselineValues(9l)
+        .baselineValues(10l)
+        .baselineValues(11l)
+        .baselineValues(12l)
+        .baselineValues(13l)
+        .baselineValues(14l)
+        .baselineValues(15l)
+        .baselineValues(16l)
+        .baselineValues(17l)
+        .baselineValues(18l)
+        .baselineValues(19l)
+        .baselineValues(20l)
+        .baselineValues(21l)
+        .baselineValues(22l)
+        .baselineValues(23l)
+        .baselineValues(24l)
+        .build()
+        .run();
   }
 
   @Test(expected = UnsupportedFunctionException.class) // DRILL-3182
@@ -165,39 +237,170 @@ public class TestWindowFunctions extends BaseTestQuery {
 
   @Test // DRILL-3188
   public void testWindowFrameEquivalentToDefault() throws Exception {
-    final String query1 = "explain plan for select sum(n_nationKey) over(partition by n_nationKey order by n_nationKey) \n" +
+    final String query1 = "select sum(n_nationKey) over(partition by n_nationKey order by n_nationKey) as col\n" +
         "from cp.`tpch/nation.parquet` t \n" +
         "order by n_nationKey";
 
-    final String query2 = "explain plan for select sum(n_nationKey) over(partition by n_nationKey order by n_nationKey \n" +
-        "range between unbounded preceding and current row) \n" +
+    final String query2 = "select sum(n_nationKey) over(partition by n_nationKey order by n_nationKey \n" +
+        "range between unbounded preceding and current row) as col \n" +
         "from cp.`tpch/nation.parquet` t \n" +
         "order by n_nationKey";
 
-    final String query3 = "explain plan for select sum(n_nationKey) over(partition by n_nationKey \n" +
-        "rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)" +
+    final String query3 = "select sum(n_nationKey) over(partition by n_nationKey \n" +
+        "rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as col \n" +
         "from cp.`tpch/nation.parquet` t \n" +
         "order by n_nationKey";
 
-    test(query1);
-    test(query2);
-    test(query3);
+    // Validate the plan
+    final String[] expectedPlan1 = {"Window.*partition \\{0\\} order by \\[0\\].*SUM\\(\\$0\\)",
+        "Scan.*columns=\\[`n_nationKey`\\].*"};
+    final String[] excludedPatterns1 = {"Scan.*columns=\\[`\\*`\\].*"};
+    PlanTestBase.testPlanMatchingPatterns(query1, expectedPlan1, excludedPatterns1);
+
+    testBuilder()
+        .sqlQuery(query1)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(0l)
+        .baselineValues(1l)
+        .baselineValues(2l)
+        .baselineValues(3l)
+        .baselineValues(4l)
+        .baselineValues(5l)
+        .baselineValues(6l)
+        .baselineValues(7l)
+        .baselineValues(8l)
+        .baselineValues(9l)
+        .baselineValues(10l)
+        .baselineValues(11l)
+        .baselineValues(12l)
+        .baselineValues(13l)
+        .baselineValues(14l)
+        .baselineValues(15l)
+        .baselineValues(16l)
+        .baselineValues(17l)
+        .baselineValues(18l)
+        .baselineValues(19l)
+        .baselineValues(20l)
+        .baselineValues(21l)
+        .baselineValues(22l)
+        .baselineValues(23l)
+        .baselineValues(24l)
+        .build()
+        .run();
+
+    final String[] expectedPlan2 = {"Window.*partition \\{0\\} order by \\[0\\].*SUM\\(\\$0\\)",
+        "Scan.*columns=\\[`n_nationKey`\\].*"};
+    final String[] excludedPatterns2 = {"Scan.*columns=\\[`\\*`\\].*"};
+    PlanTestBase.testPlanMatchingPatterns(query2, expectedPlan2, excludedPatterns2);
+
+    testBuilder()
+        .sqlQuery(query2)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(0l)
+        .baselineValues(1l)
+        .baselineValues(2l)
+        .baselineValues(3l)
+        .baselineValues(4l)
+        .baselineValues(5l)
+        .baselineValues(6l)
+        .baselineValues(7l)
+        .baselineValues(8l)
+        .baselineValues(9l)
+        .baselineValues(10l)
+        .baselineValues(11l)
+        .baselineValues(12l)
+        .baselineValues(13l)
+        .baselineValues(14l)
+        .baselineValues(15l)
+        .baselineValues(16l)
+        .baselineValues(17l)
+        .baselineValues(18l)
+        .baselineValues(19l)
+        .baselineValues(20l)
+        .baselineValues(21l)
+        .baselineValues(22l)
+        .baselineValues(23l)
+        .baselineValues(24l)
+        .build()
+        .run();
+
+    final String[] expectedPlan3 = {"Window.*partition \\{0\\}.*SUM\\(\\$0\\)",
+        "Scan.*columns=\\[`n_nationKey`\\].*"};
+    final String[] excludedPatterns3 = {"Scan.*columns=\\[`\\*`\\].*"};
+    PlanTestBase.testPlanMatchingPatterns(query3, expectedPlan3, excludedPatterns3);
+
+    testBuilder()
+        .sqlQuery(query3)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(0l)
+        .baselineValues(1l)
+        .baselineValues(2l)
+        .baselineValues(3l)
+        .baselineValues(4l)
+        .baselineValues(5l)
+        .baselineValues(6l)
+        .baselineValues(7l)
+        .baselineValues(8l)
+        .baselineValues(9l)
+        .baselineValues(10l)
+        .baselineValues(11l)
+        .baselineValues(12l)
+        .baselineValues(13l)
+        .baselineValues(14l)
+        .baselineValues(15l)
+        .baselineValues(16l)
+        .baselineValues(17l)
+        .baselineValues(18l)
+        .baselineValues(19l)
+        .baselineValues(20l)
+        .baselineValues(21l)
+        .baselineValues(22l)
+        .baselineValues(23l)
+        .baselineValues(24l)
+        .build()
+        .run();
   }
 
   @Test // DRILL-3204
   public void testWindowWithJoin() throws Exception {
-    final String query = "select sum(t1.r_regionKey) over(partition by t1.r_regionKey)  \n" +
+    final String query = "select sum(t1.r_regionKey) over(partition by t1.r_regionKey) as col \n" +
         "from cp.`tpch/region.parquet` t1, cp.`tpch/nation.parquet` t2 \n" +
         "where t1.r_regionKey = t2.n_nationKey \n" +
         "group by t1.r_regionKey";
 
-    test(query);
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{0\\}.*SUM\\(\\$0\\)",
+        "Scan.*columns=\\[`n_nationKey`\\].*",
+        "Scan.*columns=\\[`n_nationKey`\\].*"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\].*"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(0l)
+        .baselineValues(1l)
+        .baselineValues(2l)
+        .baselineValues(3l)
+        .baselineValues(4l)
+        .build()
+        .run();
   }
 
   @Test // DRILL-3298
   public void testCountEmptyPartitionByWithExchange() throws Exception {
     String query = String.format("select count(*) over (order by o_orderpriority) as cnt from dfs.`%s/multilevel/parquet` where o_custkey < 100", TEST_RES_PATH);
     try {
+      // Validate the plan
+      final String[] expectedPlan = {"Window.*partition \\{\\} order by \\[0\\].*COUNT\\(\\)",
+          "Scan.*columns=\\[`o_custkey`, `o_orderpriority`\\]"};
+      final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\]"};
+      PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
       testBuilder()
         .sqlQuery(query)
         .ordered()
@@ -223,6 +426,12 @@ public class TestWindowFunctions extends BaseTestQuery {
         "from cp.`tpch/nation.parquet` " +
         "where n_nationkey = 1";
 
+    // Validate the plan
+    final String[] expectedPlan1 = {"Window.*partition \\{0\\} order by \\[\\].*SUM\\(\\$0\\), COUNT\\(\\$0\\)",
+        "Scan.*columns=\\[`n_nationkey`\\]"};
+    final String[] excludedPatterns1 = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(avgQuery, expectedPlan1, excludedPatterns1);
+
     testBuilder()
         .sqlQuery(avgQuery)
         .unOrdered()
@@ -234,6 +443,12 @@ public class TestWindowFunctions extends BaseTestQuery {
         "from cp.`tpch/nation.parquet` " +
         "where n_nationkey = 1";
 
+    // Validate the plan
+    final String[] expectedPlan2 = {"Window.*partition \\{0\\} order by \\[\\].*SUM\\(\\$1\\), SUM\\(\\$0\\), COUNT\\(\\$0\\)",
+        "Scan.*columns=\\[`n_nationkey`\\]"};
+    final String[] excludedPatterns2 = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(varianceQuery, expectedPlan2, excludedPatterns2);
+
     testBuilder()
         .sqlQuery(varianceQuery)
         .unOrdered()
@@ -247,6 +462,12 @@ public class TestWindowFunctions extends BaseTestQuery {
     final String query = "select sum(cast(col_int as int)) over (partition by col_varchar) as col1 " +
         "from cp.`jsoninput/large_int.json` limit 1";
 
+    // Validate the plan
+    final String[] expectedPlan1 = {"Window.*partition \\{0\\} order by \\[\\].*SUM\\(\\$1\\)",
+        "Scan.*columns=\\[`col_varchar`, `col_int`\\]"};
+    final String[] excludedPatterns1 = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan1, excludedPatterns1);
+
     testBuilder()
         .sqlQuery(query)
         .unOrdered()
@@ -257,6 +478,12 @@ public class TestWindowFunctions extends BaseTestQuery {
     final String avgQuery = "select avg(cast(col_int as int)) over (partition by col_varchar) as col1 " +
         "from cp.`jsoninput/large_int.json` limit 1";
 
+    // Validate the plan
+    final String[] expectedPlan2 = {"Window.*partition \\{0\\} order by \\[\\].*SUM\\(\\$1\\), COUNT\\(\\$1\\)",
+        "Scan.*columns=\\[`col_varchar`, `col_int`\\]"};
+    final String[] excludedPatterns2 = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(avgQuery, expectedPlan2, excludedPatterns2);
+
     testBuilder()
         .sqlQuery(avgQuery)
         .unOrdered()
@@ -272,6 +499,12 @@ public class TestWindowFunctions extends BaseTestQuery {
         "FROM dfs_test.`%s` \n" +
         "WINDOW w AS (PARTITION BY columns[1] ORDER BY columns[0] DESC)", root);
 
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{1\\} order by \\[0 DESC\\].*COUNT\\(\\)",
+        "Scan.*columns=\\[`columns`\\[0\\], `columns`\\[1\\]\\]"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
     // Validate the result
     testBuilder()
         .sqlQuery(query)
@@ -296,6 +529,12 @@ public class TestWindowFunctions extends BaseTestQuery {
     final String query = "select dense_rank() over (order by l_suppkey) as rank1 " +
         " from cp.`tpch/lineitem.parquet` group by l_partkey, l_suppkey order by 1 desc limit 1";
 
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{\\} order by \\[1\\].*DENSE_RANK\\(\\)",
+        "Scan.*columns=\\[`l_partkey`, `l_suppkey`\\]"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
     testBuilder()
         .sqlQuery(query)
         .unOrdered()
@@ -307,6 +546,13 @@ public class TestWindowFunctions extends BaseTestQuery {
   @Test // DRILL-3404
   public void testWindowSumAggIsNotNull() throws Exception {
     String query = String.format("select count(*) cnt from (select sum ( c1 ) over ( partition by c2 order by c1 asc nulls first ) w_sum from dfs.`%s/window/table_with_nulls.parquet` ) sub_query where w_sum is not null", TEST_RES_PATH);
+
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{1\\} order by \\[0 ASC-nulls-first\\].*SUM\\(\\$0\\)",
+        "Scan.*columns=\\[`c1`, `c2`\\]"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
     testBuilder()
       .sqlQuery(query)
       .ordered()
@@ -322,6 +568,12 @@ public class TestWindowFunctions extends BaseTestQuery {
         "where position_id = 2 \n" +
         "window w as(partition by position_id order by employee_id)";
 
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{0\\} order by \\[1\\].*RANK\\(\\), SUM\\(\\$2\\), SUM\\(\\$1\\), SUM\\(\\$3\\)",
+        "Scan.*columns=\\[`position_id`, `employee_id`\\]"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
     testBuilder()
         .sqlQuery(query)
         .ordered()
@@ -344,6 +596,13 @@ public class TestWindowFunctions extends BaseTestQuery {
         "count(*) over(partition by a1 order by c1) as count2 \n" +
         "from dfs_test.`%s`", root);
 
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{2\\} order by \\[1\\].*COUNT\\(\\)",
+        "Window.*partition \\{0\\} order by \\[1\\].*COUNT\\(\\), SUM\\(\\$2\\)",
+        "Scan.*columns=\\[`b1`, `c1`, `a1`\\]"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
     testBuilder()
         .sqlQuery(query)
         .unOrdered()
@@ -370,6 +629,13 @@ public class TestWindowFunctions extends BaseTestQuery {
         "sum(a1)  over(partition by b1 order by c1) as sum1 \n" +
         "from dfs_test.`%s`", root);
 
+    // Validate the plan
+    final String[] expectedPlan = {"Window.*partition \\{2\\} order by \\[1\\].*COUNT\\(\\)",
+        "Window.*partition \\{0\\} order by \\[1\\].*COUNT\\(\\), SUM\\(\\$2\\)",
+        "Scan.*columns=\\[`b1`, `c1`, `a1`\\]"};
+    final String[] excludedPatterns = {"Scan.*columns=\\[`\\*`\\]"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPatterns);
+
     testBuilder()
         .sqlQuery(query)
         .unOrdered()
@@ -400,6 +666,7 @@ public class TestWindowFunctions extends BaseTestQuery {
     final String[] expectedPlan = {"Window\\(window#0=\\[window\\(partition \\{\\}.*\n" +
         ".*UnionExchange"};
     PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, new String[]{});
+
     testBuilder()
         .sqlQuery(query)
         .unOrdered()
@@ -433,6 +700,7 @@ public class TestWindowFunctions extends BaseTestQuery {
         ".*Window.*SUM\\(\\$2\\).*"
     };
     PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, new String[]{});
+
     testBuilder()
         .sqlQuery(query)
         .unOrdered()
@@ -489,6 +757,7 @@ public class TestWindowFunctions extends BaseTestQuery {
     // Validate the plan
     final String[] expectedPlan = {"Scan.*columns=\\[`n_nationkey`\\].*"};
     PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, new String[]{});
+
     testBuilder()
         .sqlQuery(query)
         .unOrdered()


[2/6] drill git commit: DRILL-3412: Add ProjectWindowTransposeRule to push Project past Window

Posted by jn...@apache.org.
DRILL-3412: Add ProjectWindowTransposeRule to push Project past Window

Fix is in CALCITE-844


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/27e4bacf
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/27e4bacf
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/27e4bacf

Branch: refs/heads/master
Commit: 27e4bacf770e9d873ebc5fc884809aaefff1c239
Parents: 9a31393
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Thu Aug 20 22:33:11 2015 -0700
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Thu Sep 10 17:45:50 2015 -0700

----------------------------------------------------------------------
 .../exec/planner/logical/DrillRuleSets.java     |  2 ++
 .../apache/drill/exec/TestWindowFunctions.java  | 23 ++++++++++++++++++++
 2 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/27e4bacf/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
index 3ad617a..ab70d93 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
@@ -28,6 +28,7 @@ import org.apache.calcite.rel.rules.FilterSetOpTransposeRule;
 import org.apache.calcite.rel.rules.JoinPushExpressionsRule;
 import org.apache.calcite.rel.rules.JoinPushThroughJoinRule;
 import org.apache.calcite.rel.rules.ProjectRemoveRule;
+import org.apache.calcite.rel.rules.ProjectWindowTransposeRule;
 import org.apache.calcite.rel.rules.ReduceExpressionsRule;
 import org.apache.calcite.rel.rules.SortRemoveRule;
 import org.apache.calcite.rel.rules.UnionToDistinctRule;
@@ -133,6 +134,7 @@ public class DrillRuleSets {
       DrillPushProjectPastJoinRule.INSTANCE,
       DrillPushProjIntoScan.INSTANCE,
       DrillProjectSetOpTransposeRule.INSTANCE,
+      ProjectWindowTransposeRule.INSTANCE,
 
       /*
        Convert from Calcite Logical to Drill Logical Rules.

http://git-wip-us.apache.org/repos/asf/drill/blob/27e4bacf/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 dbbc777..0ce82f5 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
@@ -478,4 +478,27 @@ public class TestWindowFunctions extends BaseTestQuery {
         .build()
         .run();
   }
+
+  @Test // see DRILL-3657
+  public void testProjectPushPastWindow() throws Exception {
+    String query = "select sum(n_nationkey) over(partition by 1 order by 1) as col1, \n" +
+            "count(n_nationkey) over(partition by 1 order by 1) as col2 \n" +
+            "from cp.`tpch/nation.parquet` \n" +
+            "limit 5";
+
+    // Validate the plan
+    final String[] expectedPlan = {"Scan.*columns=\\[`n_nationkey`\\].*"};
+    PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, new String[]{});
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col1", "col2")
+        .baselineValues(300l, 25l)
+        .baselineValues(300l, 25l)
+        .baselineValues(300l, 25l)
+        .baselineValues(300l, 25l)
+        .baselineValues(300l, 25l)
+        .build()
+        .run();
+  }
 }
\ No newline at end of file