You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/06/28 00:27:49 UTC

[2/7] git commit: More tests for WITH ... ORDER BY.

More tests for WITH ... ORDER BY.


Project: http://git-wip-us.apache.org/repos/asf/incubator-optiq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-optiq/commit/347eabdd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-optiq/tree/347eabdd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-optiq/diff/347eabdd

Branch: refs/heads/master
Commit: 347eabdd6ea600bcd17df607bdae90ea57ea221a
Parents: a1557c2
Author: Julian Hyde <ju...@gmail.com>
Authored: Sun Jun 22 21:44:29 2014 -0700
Committer: Julian Hyde <ju...@gmail.com>
Committed: Sun Jun 22 21:44:29 2014 -0700

----------------------------------------------------------------------
 .../net/hydromatic/optiq/test/JdbcTest.java     | 10 +++---
 .../eigenbase/test/SqlToRelConverterTest.java   | 18 ++++++++++
 .../eigenbase/test/SqlToRelConverterTest.xml    | 38 ++++++++++++++++++++
 .../hydromatic/optiq/impl/tpcds/TpcdsTest.java  | 12 +++----
 4 files changed, 67 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/347eabdd/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java b/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
index dcbe60c..0fdf109 100644
--- a/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
+++ b/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
@@ -2852,8 +2852,8 @@ public class JdbcTest {
         .with(OptiqAssert.Config.REGULAR)
         .query(
             "with emp2 as (select * from \"hr\".\"emps\")\n"
-                + "select * from emp2\n"
-                + "order by \"deptno\" desc, \"empid\" desc")
+            + "select * from emp2\n"
+            + "order by \"deptno\" desc, \"empid\" desc")
         .returns(
             "empid=200; deptno=20; name=Eric; salary=8000.0; commission=500\n"
             + "empid=150; deptno=10; name=Sebastian; salary=7000.0; commission=null\n"
@@ -4524,7 +4524,8 @@ public class JdbcTest {
         .returns("P0=0; P1=1; P2=2\n");
   }
 
-  /** Test for {@link EigenbaseNewResource#requireDefaultConstructor(String)}. */
+  /** Test for
+   * {@link org.eigenbase.resource.EigenbaseNewResource#requireDefaultConstructor(String)}. */
   @Test public void testUserDefinedFunction2() throws Exception {
     withBadUdf(AwkwardFunction.class)
         .connectThrows(
@@ -4595,7 +4596,8 @@ public class JdbcTest {
         .returnsUnordered("deptno=20; P=20", "deptno=10; P=30");
   }
 
-  /** Test for {@link EigenbaseNewResource#firstParameterOfAdd(String)}. */
+  /** Test for
+   * {@link org.eigenbase.resource.EigenbaseNewResource#firstParameterOfAdd(String)}. */
   @Test public void testUserDefinedAggregateFunction3() throws Exception {
     withBadUdf(SumFunctionBadIAdd.class).connectThrows(
         "Caused by: java.lang.RuntimeException: In user-defined aggregate class 'net.hydromatic.optiq.test.JdbcTest$SumFunctionBadIAdd', first parameter to 'add' method must be the accumulator (the return type of the 'init' method)");

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/347eabdd/core/src/test/java/org/eigenbase/test/SqlToRelConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eigenbase/test/SqlToRelConverterTest.java b/core/src/test/java/org/eigenbase/test/SqlToRelConverterTest.java
index f474b1f..03600c4 100644
--- a/core/src/test/java/org/eigenbase/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/eigenbase/test/SqlToRelConverterTest.java
@@ -436,6 +436,24 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
         "${plan}");
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/OPTIQ-309">[OPTIQ-309]
+   * WITH ... ORDER BY query gives AssertionError</a>. */
+  @Test public void testWithOrder() {
+    check("with emp2 as (select * from emp)\n"
+        + "select * from emp2 order by deptno",
+        "${plan}");
+  }
+
+  @Test public void testWithUnionOrder() {
+    check("with emp2 as (select empno, deptno as x from emp)\n"
+        + "select * from emp2\n"
+        + "union all\n"
+        + "select * from emp2\n"
+        + "order by empno + x",
+        "${plan}");
+  }
+
   @Test public void testWithUnion() {
     check("with emp2 as (select * from emp where deptno > 10)\n"
       + "select empno from emp2 where deptno < 30 union all select deptno from emp",

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/347eabdd/core/src/test/resources/org/eigenbase/test/SqlToRelConverterTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/eigenbase/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/eigenbase/test/SqlToRelConverterTest.xml
index 56733e6..c7bbdd5 100644
--- a/core/src/test/resources/org/eigenbase/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/eigenbase/test/SqlToRelConverterTest.xml
@@ -1807,4 +1807,42 @@ UnionRel(all=[true])
 ]]>
         </Resource>
     </TestCase>
+    <TestCase name="testWithOrder">
+        <Resource name="sql">
+            <![CDATA[with emp2 as (select * from emp)
+select * from emp2 order by deptno]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+SortRel(sort0=[$7], dir0=[ASC])
+  ProjectRel(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+    ProjectRel(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+      ProjectRel(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+        TableAccessRel(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
+    <TestCase name="testWithUnionOrder">
+        <Resource name="sql">
+            <![CDATA[with emp2 as (select empno, deptno as x from emp)
+select * from emp2
+union all
+select * from emp2
+order by empno + x]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+ProjectRel(EMPNO=[$0], X=[$1])
+  SortRel(sort0=[$2], dir0=[ASC])
+    ProjectRel(EMPNO=[$0], X=[$1], EXPR$2=[+($0, $1)])
+      UnionRel(all=[true])
+        ProjectRel(EMPNO=[$0], X=[$1])
+          ProjectRel(EMPNO=[$0], X=[$7])
+            TableAccessRel(table=[[CATALOG, SALES, EMP]])
+        ProjectRel(EMPNO=[$0], X=[$1])
+          ProjectRel(EMPNO=[$0], X=[$7])
+            TableAccessRel(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
 </Root>

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/347eabdd/plus/src/test/java/net/hydromatic/optiq/impl/tpcds/TpcdsTest.java
----------------------------------------------------------------------
diff --git a/plus/src/test/java/net/hydromatic/optiq/impl/tpcds/TpcdsTest.java b/plus/src/test/java/net/hydromatic/optiq/impl/tpcds/TpcdsTest.java
index fb90a87..17319e5 100644
--- a/plus/src/test/java/net/hydromatic/optiq/impl/tpcds/TpcdsTest.java
+++ b/plus/src/test/java/net/hydromatic/optiq/impl/tpcds/TpcdsTest.java
@@ -83,17 +83,16 @@ public class TpcdsTest {
         .returnsCount(750000);
   }
 
-  @Ignore("assert fail in registerQuery")
   @Test public void testQuery01() {
-    checkQuery(1);
+    checkQuery(1).runs();
   }
 
   @Ignore("takes too long to optimize")
   @Test public void testQuery72() {
-    checkQuery(72);
+    checkQuery(72).runs();
   }
 
-  private void checkQuery(int i) {
+  private OptiqAssert.AssertQuery checkQuery(int i) {
     final Query query = Query.of(i);
     String sql = query.sql(-1, new Random(0));
     switch (i) {
@@ -101,9 +100,8 @@ public class TpcdsTest {
       // Work around OPTIQ-304: Support '<DATE> + <INTEGER>'.
       sql = sql.replace("+ 5", "+ interval '5' day");
     }
-    with()
-        .query(sql.replaceAll("tpcds\\.", "tpcds_01."))
-        .runs();
+    return with()
+        .query(sql.replaceAll("tpcds\\.", "tpcds_01."));
   }
 }