Repository: calcite Updated Branches: refs/heads/master 520c0ccc9 -> e046be23d
[CALCITE-1781] Allow expression in CUBE and ROLLUP Seems to be already working; added tests. Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/5ee895d3 Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/5ee895d3 Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/5ee895d3 Branch: refs/heads/master Commit: 5ee895d3021028b5412833b8cd37deda1b5af4ea Parents: 520c0cc Author: Julian Hyde <[email protected]> Authored: Tue May 9 12:19:56 2017 -0700 Committer: Julian Hyde <[email protected]> Committed: Tue May 9 12:39:30 2017 -0700 ---------------------------------------------------------------------- .../apache/calcite/test/SqlValidatorTest.java | 26 ++++++ core/src/test/resources/sql/agg.iq | 87 ++++++++++++++++++++ 2 files changed, 113 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/5ee895d3/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 03faca7..ae1e1f8 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -4928,6 +4928,32 @@ public class SqlValidatorTest extends SqlValidatorTestCase { .fails("(?s)Cannot apply '\\+' to arguments of type.*"); } + /** Test case for + * <a href="https://issues.apache.org/jira/browse/CALCITE-1781">[CALCITE-1781] + * Allow expression in CUBE and ROLLUP</a>. */ + @Test public void testCubeExpression() { + final String sql = "select deptno + 1\n" + + "from emp\n" + + "group by cube(deptno + 1)"; + sql(sql).ok(); + final String sql2 = "select deptno + 2 - 2\n" + + "from emp\n" + + "group by cube(deptno + 2, empno)"; + sql(sql2).ok(); + final String sql3 = "select ^deptno^\n" + + "from emp\n" + + "group by cube(deptno + 1)"; + sql(sql3).fails("Expression 'DEPTNO' is not being grouped"); + final String sql4 = "select ^deptno^ + 10\n" + + "from emp\n" + + "group by rollup(empno, deptno + 10 - 10)"; + sql(sql4).fails("Expression 'DEPTNO' is not being grouped"); + final String sql5 = "select deptno + 10\n" + + "from emp\n" + + "group by rollup(deptno + 10 - 10, deptno)"; + sql(sql5).ok(); + } + /** Unit test for * {@link org.apache.calcite.sql.validate.SqlValidatorUtil#rollup}. */ @Test public void testRollupBitSets() { http://git-wip-us.apache.org/repos/asf/calcite/blob/5ee895d3/core/src/test/resources/sql/agg.iq ---------------------------------------------------------------------- diff --git a/core/src/test/resources/sql/agg.iq b/core/src/test/resources/sql/agg.iq index 464c79a..51ab512 100755 --- a/core/src/test/resources/sql/agg.iq +++ b/core/src/test/resources/sql/agg.iq @@ -619,6 +619,93 @@ from emp group by cube(deptno, gender); !ok +# [CALCITE-1781] Allow expression in CUBE and ROLLUP +select deptno + 1 as d1, deptno + 1 - 1 as d0, count(*) as c +from emp +group by rollup(deptno + 1); ++----+----+---+ +| D1 | D0 | C | ++----+----+---+ +| 11 | 10 | 2 | +| 21 | 20 | 1 | +| 31 | 30 | 2 | +| 51 | 50 | 2 | +| 61 | 60 | 1 | +| | | 1 | +| | | 9 | ++----+----+---+ +(7 rows) + +!ok + +select mod(deptno, 20) as d, count(*) as c, gender as g +from emp +group by cube(mod(deptno, 20), gender); ++----+---+---+ +| D | C | G | ++----+---+---+ +| 0 | 1 | F | +| 0 | 1 | M | +| 0 | 2 | | +| 10 | 2 | M | +| 10 | 4 | F | +| 10 | 6 | | +| | 1 | F | +| | 1 | | +| | 3 | M | +| | 6 | F | +| | 9 | | ++----+---+---+ +(11 rows) + +!ok + +select mod(deptno, 20) as d, count(*) as c, gender as g +from emp +group by rollup(mod(deptno, 20), gender); ++----+---+---+ +| D | C | G | ++----+---+---+ +| 0 | 1 | F | +| 0 | 1 | M | +| 0 | 2 | | +| 10 | 2 | M | +| 10 | 4 | F | +| 10 | 6 | | +| | 1 | F | +| | 1 | | +| | 9 | | ++----+---+---+ +(9 rows) + +!ok + +select count(*) as c +from emp +group by cube(1); ++---+ +| C | ++---+ +| 9 | +| 9 | ++---+ +(2 rows) + +!ok + +select count(*) as c +from emp +group by rollup(1); ++---+ +| C | ++---+ +| 9 | +| 9 | ++---+ +(2 rows) + +!ok + !use scott # [KYLIN-751] Max on negative double values is not working
