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 2015/04/06 19:25:12 UTC

incubator-calcite git commit: [CALCITE-662] Query validation fails when an ORDER BY clause is used with WITH CLAUSE

Repository: incubator-calcite
Updated Branches:
  refs/heads/master 38a4dd416 -> 7d522dc93


[CALCITE-662] Query validation fails when an ORDER BY clause is used with WITH CLAUSE


Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/7d522dc9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/7d522dc9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/7d522dc9

Branch: refs/heads/master
Commit: 7d522dc93f776ca019366c442dc54f6f8c5fd6b1
Parents: 38a4dd4
Author: Julian Hyde <jh...@apache.org>
Authored: Mon Apr 6 00:33:44 2015 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Apr 6 00:33:44 2015 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/calcite/sql/SqlWith.java  | 17 +++++++++++++++--
 .../org/apache/calcite/test/SqlValidatorTest.java  | 16 ++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/7d522dc9/core/src/main/java/org/apache/calcite/sql/SqlWith.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWith.java b/core/src/main/java/org/apache/calcite/sql/SqlWith.java
index 4e772ac..f0cd2c3 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlWith.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlWith.java
@@ -28,8 +28,8 @@ import java.util.List;
  * The WITH clause of a query. It wraps a SELECT, UNION, or INTERSECT.
  */
 public class SqlWith extends SqlCall {
-  public final SqlNodeList withList;
-  public final SqlNode body;
+  public SqlNodeList withList;
+  public SqlNode body;
 
   //~ Constructors -----------------------------------------------------------
 
@@ -53,6 +53,19 @@ public class SqlWith extends SqlCall {
     return ImmutableList.of(withList, body);
   }
 
+  @Override public void setOperand(int i, SqlNode operand) {
+    switch (i) {
+    case 0:
+      withList = (SqlNodeList) operand;
+      break;
+    case 1:
+      body = operand;
+      break;
+    default:
+      throw new AssertionError(i);
+    }
+  }
+
   @Override public void validate(SqlValidator validator,
       SqlValidatorScope scope) {
     validator.validateWith(this, scope);

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/7d522dc9/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index ec3fed1..a24e16a 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -5633,6 +5633,22 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
             + "select * from e as e1, e as e2 order by e1.empno").ok();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-662">[CALCITE-662]
+   * Query validation fails when an ORDER BY clause is used with WITH
+   * CLAUSE</a>. */
+  @Test public void testWithOrderInParentheses() {
+    sql("with e as (select * from emp)\n"
+            + "(select e.empno from e order by e.empno)").ok();
+    sql("with e as (select * from emp)\n"
+            + "(select e.empno from e order by 1)").ok();
+    sql("with e as (select * from emp)\n"
+            + "(select ee.empno from e as ee order by ee.deptno)").ok();
+    // worked even before CALCITE-662 fixed
+    sql("with e as (select * from emp)\n"
+            + "(select e.empno from e)").ok();
+  }
+
   @Test public void testOrderUnion() {
     check("select empno, sal from emp "
         + "union all "