|
11 | 11 |
|
12 | 12 | public abstract class BaseSqlParserFacadeTest { |
13 | 13 |
|
14 | | -// @Test(groups = {"integration"}) |
15 | | -// public void testWithComments() throws Exception { |
16 | | -// assertEquals(SqlParser.parseStatementType(" /* INSERT TESTING */\n SELECT 1 AS num").getType(), SqlParser.StatementType.SELECT); |
17 | | -// assertEquals(SqlParser.parseStatementType("/* SELECT TESTING */\n INSERT INTO test_table VALUES (1)").getType(), SqlParser.StatementType.INSERT); |
18 | | -// assertEquals(SqlParser.parseStatementType("/* INSERT TESTING */\n\n\n UPDATE test_table SET num = 2").getType(), SqlParser.StatementType.UPDATE); |
19 | | -// assertEquals(SqlParser.parseStatementType("-- INSERT TESTING */\n SELECT 1 AS num").getType(), SqlParser.StatementType.SELECT); |
20 | | -// assertEquals(SqlParser.parseStatementType(" -- SELECT TESTING \n -- SELECT AGAIN \n INSERT INTO test_table VALUES (1)").getType(), SqlParser.StatementType.INSERT); |
21 | | -// assertEquals(SqlParser.parseStatementType(" SELECT 42 -- INSERT TESTING").getType(), SqlParser.StatementType.SELECT); |
22 | | -// assertEquals(SqlParser.parseStatementType("#! INSERT TESTING \n SELECT 1 AS num").getType(), SqlParser.StatementType.SELECT); |
23 | | -// assertEquals(SqlParser.parseStatementType("#!INSERT TESTING \n SELECT 1 AS num").getType(), SqlParser.StatementType.SELECT); |
24 | | -// assertEquals(SqlParser.parseStatementType("# INSERT TESTING \n SELECT 1 AS num").getType(), SqlParser.StatementType.SELECT); |
25 | | -// assertEquals(SqlParser.parseStatementType("#INSERT TESTING \n SELECT 1 AS num").getType(), SqlParser.StatementType.SELECT); |
26 | | -// assertEquals(SqlParser.parseStatementType("\nINSERT TESTING \n SELECT 1 AS num").getType(), SqlParser.StatementType.INSERT_INTO_SELECT); |
27 | | -// assertEquals(SqlParser.parseStatementType(" \n INSERT TESTING \n SELECT 1 AS num").getType(), SqlParser.StatementType.INSERT_INTO_SELECT); |
28 | | -// assertEquals(SqlParser.parseStatementType("INSERT INTO t SELECT 1 AS num").getType(), SqlParser.StatementType.INSERT_INTO_SELECT); |
29 | | -// assertEquals(SqlParser.parseStatementType("select 1 AS num").getType(), SqlParser.StatementType.SELECT); |
30 | | -// assertEquals(SqlParser.parseStatementType("insert into test_table values (1)").getType(), SqlParser.StatementType.INSERT); |
31 | | -// assertEquals(SqlParser.parseStatementType("update test_table set num = 2").getType(), SqlParser.StatementType.UPDATE); |
32 | | -// assertEquals(SqlParser.parseStatementType("delete from test_table where num = 2").getType(), SqlParser.StatementType.DELETE); |
33 | | -// assertEquals(SqlParser.parseStatementType("sElEcT 1 AS num").getType(), SqlParser.StatementType.SELECT); |
34 | | -// assertEquals(SqlParser.parseStatementType(null).getType(), SqlParser.StatementType.OTHER); |
35 | | -// assertEquals(SqlParser.parseStatementType("").getType(), SqlParser.StatementType.OTHER); |
36 | | -// assertEquals(SqlParser.parseStatementType(" ").getType(), SqlParser.StatementType.OTHER); |
37 | | -// } |
38 | | -// |
39 | | -// @Test(groups = {"integration"}) |
40 | | -// public void testParseStatementWithClause() throws Exception { |
41 | | -// assertEquals(SqlParser.parseStatementType("with data as (SELECT number FROM numbers(100)) select * from data").getType(), SqlParser.StatementType.SELECT); |
42 | | -// } |
43 | | - |
44 | 14 | private SqlParserFacade parser; |
45 | 15 |
|
46 | 16 | public BaseSqlParserFacadeTest(String name) throws Exception { |
@@ -353,9 +323,30 @@ public Object[][] testMiscStmtDp() { |
353 | 323 | {"insert into t (i, t) values (1, timestamp '2010-01-01 00:00:00')", 0}, |
354 | 324 | {"insert into t (i, t) values (1, date '2010-01-01')", 0}, |
355 | 325 | {"SELECT timestamp '2010-01-01 00:00:00' as ts, date '2010-01-01' as d", 0}, |
| 326 | + {INSERT_WITH_COMMENTS, 4}, |
| 327 | + {" /* INSERT TESTING ?? */\n SELECT ? AS num", 1}, |
| 328 | + {"/* SELECT ? TESTING */\n INSERT INTO test_table VALUES (?)", 1}, |
| 329 | + {"/* INSERT ? T??ESTING */\n\n\n UPDATE test_table SET num = ?", 1}, |
| 330 | + {"-- INSERT ? TESTING */\n SELECT ? AS num", 1}, |
| 331 | + {" -- SELECT ? TESTING \n -- SELECT AGAIN ?\n INSERT INTO test_table VALUES (?)", 1}, |
| 332 | + {" SELECT ? -- INSERT ? TESTING", 1}, |
| 333 | + {"#! INSERT ? TESTING \n SELECT ? AS num", 1}, |
| 334 | + {"#!INSERT ? TESTING \n SELECT ? AS num", 1}, |
| 335 | + {"# INSERT ? TESTING \n SELECT ? AS num", 1}, |
| 336 | + {"#INSERT ? TESTING \n SELECT ? AS num", 1}, |
| 337 | + {"\nINSERT INTO TESTING \n SELECT ? AS num", 1}, |
| 338 | + {" \n INSERT INTO TESTING \n SELECT ? AS num", 1}, |
| 339 | + {" SELECT '##?0.1' as f, ? as a\n #this is debug \n FROM table", 1}, |
| 340 | + {"WITH '#!?0.1' as f, ? as a\n #this is debug \n SELECT * FROM a", 1}, |
356 | 341 | }; |
357 | 342 | } |
358 | 343 |
|
| 344 | + private static final String INSERT_WITH_COMMENTS = "-- line comment1 ?\n" |
| 345 | + + "# line comment2 ?\n" |
| 346 | + + "#! line comment3 ?\n" |
| 347 | + + "/* block comment ? \n */" |
| 348 | + + "INSERT INTO `with_complex_id`(`v?``1`, \"v?\"\"2\",`v?\\`3`, \"v?\\\"4\") VALUES (?, ?, ?, ?);"; |
| 349 | + |
359 | 350 | private static final String INSERT_INLINE_DATA = |
360 | 351 | "INSERT INTO `interval_15_XUTLZWBLKMNZZPRZSKRF`.`checkins` (`timestamp`, `id`) " + |
361 | 352 | "VALUES ((`now64`(9) + INTERVAL -225 second), 1)"; |
|
0 commit comments