You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by da...@apache.org on 2019/07/03 04:11:08 UTC

[calcite] branch master updated: [CALCITE-3168] Add test for invalid literal of sql parser

This is an automated email from the ASF dual-hosted git repository.

danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new 021fabe  [CALCITE-3168] Add test for invalid literal of sql parser
021fabe is described below

commit 021fabe2a77264b388a3b681b78bc7e51fb2d978
Author: yuzhao.cyz <yu...@alibaba-inc.com>
AuthorDate: Wed Jul 3 10:20:25 2019 +0800

    [CALCITE-3168] Add test for invalid literal of sql parser
    
    This patch also merge the redundant sql statements with
    `SqlParserTest.Sql#sansCarets`.
---
 .../apache/calcite/sql/parser/SqlParserTest.java   | 42 ++++++++++++++++------
 1 file changed, 31 insertions(+), 11 deletions(-)

diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
index d7e18e0..aa16124 100644
--- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -2227,9 +2227,8 @@ public class SqlParserTest {
   @Test public void testSetMinus() {
     final String pattern =
         "MINUS is not allowed under the current SQL conformance level";
-    final String sql0 = "select col1 from table1 ^MINUS^ select col1 from table2";
-    final String sql1 = "select col1 from table1 MINUS select col1 from table2";
-    sql(sql0).fails(pattern);
+    final String sql = "select col1 from table1 ^MINUS^ select col1 from table2";
+    sql(sql).fails(pattern);
 
     conformance = SqlConformanceEnum.ORACLE_10;
     final String expected = "(SELECT `COL1`\n"
@@ -2237,7 +2236,7 @@ public class SqlParserTest {
         + "EXCEPT\n"
         + "SELECT `COL1`\n"
         + "FROM `TABLE2`)";
-    sql(sql1).ok(expected);
+    sql(sql).sansCarets().ok(expected);
 
     final String sql2 =
         "select col1 from table1 MINUS ALL select col1 from table2";
@@ -2449,24 +2448,22 @@ public class SqlParserTest {
   @Test public void testApply() {
     final String pattern =
         "APPLY operator is not allowed under the current SQL conformance level";
-    final String sql0 = "select * from dept\n"
+    final String sql = "select * from dept\n"
         + "cross apply table(ramp(deptno)) as t(a^)^";
-    final String sql1 = "select * from dept\n"
-        + "cross apply table(ramp(deptno)) as t(a)";
-    sql(sql0).fails(pattern);
+    sql(sql).fails(pattern);
 
     conformance = SqlConformanceEnum.SQL_SERVER_2008;
     final String expected = "SELECT *\n"
         + "FROM `DEPT`\n"
         + "CROSS JOIN LATERAL TABLE(`RAMP`(`DEPTNO`)) AS `T` (`A`)";
-    sql(sql1).ok(expected);
+    sql(sql).sansCarets().ok(expected);
 
     // Supported in Oracle 12 but not Oracle 10
     conformance = SqlConformanceEnum.ORACLE_10;
-    sql(sql0).fails(pattern);
+    sql(sql).fails(pattern);
 
     conformance = SqlConformanceEnum.ORACLE_12;
-    sql(sql1).ok(expected);
+    sql(sql).sansCarets().ok(expected);
   }
 
   /** Tests OUTER APPLY. */
@@ -2551,6 +2548,29 @@ public class SqlParserTest {
             + "from emp as x tablesample bernoulli(50)",
         "SELECT *\n"
             + "FROM `EMP` AS `X` TABLESAMPLE BERNOULLI(50.0)");
+
+    check(
+        "select * "
+            + "from emp as x "
+            + "tablesample bernoulli(50) REPEATABLE(10) ",
+        "SELECT *\n"
+            + "FROM `EMP` AS `X` TABLESAMPLE BERNOULLI(50.0) REPEATABLE(10)");
+
+    // test repeatable with invalid int literal.
+    checkFails(
+        "select * "
+            + "from emp as x "
+            + "tablesample bernoulli(50) REPEATABLE(^100000000000000000000^) ",
+        "Literal '100000000000000000000' "
+            + "can not be parsed to type 'java\\.lang\\.Integer'");
+
+    // test repeatable with invalid negative int literal.
+    checkFails(
+        "select * "
+            + "from emp as x "
+            + "tablesample bernoulli(50) REPEATABLE(-^100000000000000000000^) ",
+        "Literal '100000000000000000000' "
+            + "can not be parsed to type 'java\\.lang\\.Integer'");
   }
 
   @Test public void testLiteral() {