@Test public void testInsertValuesRawDefault() { final String expected = "INSERT INTO `EMPS`\n" + "VALUES (ROW(DEFAULT))"; sql("insert into emps ^values^ default") .fails("(?s).*Encountered \"values default\" at .*"); sql("insert into emps values (default)") .ok(expected) .node(not(isDdl())); }
@Test public void testInsertValuesRawDefault() { final String expected = "INSERT INTO `EMPS`\n" + "VALUES (ROW(DEFAULT))"; sql("insert into emps ^values^ default") .fails("(?s).*Encountered \"values default\" at .*"); sql("insert into emps values (default)") .ok(expected) .node(not(isDdl())); }
@Test public void testTableStarColumnFails() { sql("select emp.*^.^xx from emp") .fails("(?s).*Encountered \".\" .*"); }
@Test public void testLimitUnion() { // LIMIT inside UNION not allowed sql("select a from t limit 10\n" + "^union^ all\n" + "select b from t order by b") .fails("(?s).*Encountered \"union\" at .*"); }
@Test public void testOrderUnion() { // ORDER BY inside UNION not allowed sql("select a from t order by a\n" + "^union^ all\n" + "select b from t order by b") .fails("(?s).*Encountered \"union\" at .*"); }
@Test public void testGroupByCube2() { sql("select deptno from emp\n" + "group by cube ((a, b), (c, d)) order by a") .ok("SELECT `DEPTNO`\n" + "FROM `EMP`\n" + "GROUP BY CUBE((`A`, `B`), (`C`, `D`))\n" + "ORDER BY `A`"); sql("select deptno from emp\n" + "group by cube (^)") .fails("(?s)Encountered \"\\)\" at .*"); }
@Test public void testExtendedSqlStmt() { sql("DESCRIBE SPACE POWER") .node(new IsNull<SqlNode>()); sql("DESCRIBE SEA ^POWER^") .fails("(?s)Encountered \"POWER\" at line 1, column 14..*"); } }
@Test public void testOrderUnion() { // ORDER BY inside UNION not allowed sql("select a from t order by a\n" + "^union^ all\n" + "select b from t order by b") .fails("(?s).*Encountered \"union\" at .*"); }
@Test public void testGroupByRollup() { sql("select deptno from emp\n" + "group by rollup (deptno, deptno + 1, gender)") .ok("SELECT `DEPTNO`\n" + "FROM `EMP`\n" + "GROUP BY ROLLUP(`DEPTNO`, (`DEPTNO` + 1), `GENDER`)"); // Nested rollup not ok sql("select deptno from emp\n" + "group by rollup (deptno^, rollup(e, d))") .fails("(?s)Encountered \", rollup\" at .*"); }
protected void checkFails( String sql, String expectedMsgPattern) { sql(sql).fails(expectedMsgPattern); }
/** Even in SQL Server conformance mode, we do not yet support * 'function(args)' as an abbreviation for 'table(function(args)'. */ @Test public void testOuterApplyFunctionFails() { conformance = SqlConformanceEnum.SQL_SERVER_2008; final String sql = "select * from dept outer apply ramp(deptno^)^)"; sql(sql).fails("(?s).*Encountered \"\\)\" at .*"); }
/** MINUS is a <b>reserved</b> keyword in Calcite in all conformances, even * in the default conformance, where it is not allowed as an alternative to * EXCEPT. (It is reserved in Oracle but not in any version of the SQL * standard.) */ @Test public void testMinusIsReserved() { sql("select ^minus^ from t") .fails("(?s).*Encountered \"minus from\" at .*"); sql("select ^minus^ select") .fails("(?s).*Encountered \"minus select\" at .*"); sql("select * from t ^as^ minus where x < y") .fails("(?s).*Encountered \"as minus\" at .*"); }
@Test public void testWithinGroupClause3() { final String sql = "select collect(col2) within group (^)^ " + "from t order by col1 limit 10"; sql(sql).fails("(?s).*Encountered \"\\)\" at line 1, column 36\\..*"); }
@Test public void testExtendedSqlStmt() { sql("DESCRIBE SPACE POWER") .node(new IsNull<SqlNode>()); sql("DESCRIBE SEA ^POWER^") .fails("(?s)Encountered \"POWER\" at line 1, column 14..*"); } }
@Test public void testGroupByRollup() { sql("select deptno from emp\n" + "group by rollup (deptno, deptno + 1, gender)") .ok("SELECT `DEPTNO`\n" + "FROM `EMP`\n" + "GROUP BY ROLLUP(`DEPTNO`, (`DEPTNO` + 1), `GENDER`)"); // Nested rollup not ok sql("select deptno from emp\n" + "group by rollup (deptno^, rollup(e, d))") .fails("(?s)Encountered \", rollup\" at .*"); }
@Test public void testLimitUnion() { // LIMIT inside UNION not allowed sql("select a from t limit 10\n" + "^union^ all\n" + "select b from t order by b") .fails("(?s).*Encountered \"union\" at .*"); }
@Test public void testGroupByCube2() { sql("select deptno from emp\n" + "group by cube ((a, b), (c, d)) order by a") .ok("SELECT `DEPTNO`\n" + "FROM `EMP`\n" + "GROUP BY CUBE((`A`, `B`), (`C`, `D`))\n" + "ORDER BY `A`"); sql("select deptno from emp\n" + "group by cube (^)") .fails("(?s)Encountered \"\\)\" at .*"); }
/** Even in SQL Server conformance mode, we do not yet support * 'function(args)' as an abbreviation for 'table(function(args)'. */ @Test public void testOuterApplyFunctionFails() { conformance = SqlConformanceEnum.SQL_SERVER_2008; final String sql = "select * from dept outer apply ramp(deptno^)^)"; sql(sql).fails("(?s).*Encountered \"\\)\" at .*"); }
protected void checkFails( String sql, String expectedMsgPattern) { sql(sql).fails(expectedMsgPattern); }
/** MINUS is a <b>reserved</b> keyword in Calcite in all conformances, even * in the default conformance, where it is not allowed as an alternative to * EXCEPT. (It is reserved in Oracle but not in any version of the SQL * standard.) */ @Test public void testMinusIsReserved() { sql("select ^minus^ from t") .fails("(?s).*Encountered \"minus from\" at .*"); sql("select ^minus^ select") .fails("(?s).*Encountered \"minus select\" at .*"); sql("select * from t ^as^ minus where x < y") .fails("(?s).*Encountered \"as minus\" at .*"); }