Skip to content

Commit f02382f

Browse files
committed
Fixed some keyword issues
1 parent fdfc35b commit f02382f

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/parser/antlr4/ClickHouseLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ WORKLOAD : W O R K L O A D;
377377
WRITABLE : W R I T A B L E;
378378
YEAR : Y E A R | Y Y Y Y;
379379
ZKPATH : Z K P A T H;
380+
SUM : S U M;
381+
AVG : A V G;
380382

381383
JSON_FALSE : 'false';
382384
JSON_TRUE : 'true';

jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/parser/antlr4/ClickHouseParser.g4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ fromClause
513513
| FROM identifier LPAREN JDBC_PARAM_PLACEHOLDER RPAREN
514514
| FROM selectStmt
515515
| FROM identifier LPAREN viewParam (COMMA viewParam)? RPAREN
516+
| FROM tableFunctionExpr
516517
;
517518

518519
viewParam
@@ -1315,6 +1316,7 @@ keyword
13151316
| LIVE
13161317
| LOCAL
13171318
| LOGS
1319+
| LOG
13181320
| MATERIALIZE
13191321
| MATERIALIZED
13201322
| MAX
@@ -1345,6 +1347,7 @@ keyword
13451347
| RANGE
13461348
| RELOAD
13471349
| REMOVE
1350+
| REMOTE
13481351
| RENAME
13491352
| REPLACE
13501353
| REPLICA
@@ -1391,7 +1394,9 @@ keyword
13911394
| USE
13921395
| USING
13931396
| USER
1397+
| USERS
13941398
| UUID
1399+
| URL
13951400
| VALUES
13961401
| VIEW
13971402
| VOLUME
@@ -1401,6 +1406,10 @@ keyword
14011406
| WINDOW
14021407
| WITH
14031408
| QUERIES
1409+
| SUM
1410+
| AVG
1411+
| REFRESH
1412+
| EXPLAIN
14041413
;
14051414

14061415
keywordForAlias

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/SqlParserFacade.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ParsedStatement parsedStatement(String sql) {
4444
}
4545
// TODO: set roles
4646
stmt.setInsert(parsedStmt.getStatementType() == StatementType.INSERT);
47-
stmt.setHasErrors(false);
47+
stmt.setHasErrors(parsedStmt.getStatementType() == StatementType.UNKNOWN);
4848
stmt.setHasResultSet(isStmtWithResultSet(parsedStmt));
4949
return stmt;
5050
}
@@ -64,7 +64,7 @@ public ParsedPreparedStatement parsePreparedStatement(String sql) {
6464
stmt.setUseDatabase(parsedStmt.getDatabase());
6565
}
6666
stmt.setInsert(parsedStmt.getStatementType() == StatementType.INSERT);
67-
stmt.setHasErrors(false);
67+
stmt.setHasErrors(parsedStmt.getStatementType() == StatementType.UNKNOWN);
6868
stmt.setHasResultSet(isStmtWithResultSet(parsedStmt));
6969
stmt.setTable(parsedStmt.getTable());
7070
stmt.setInsertWithSelect(parsedStmt.containsKeyword("SELECT") && (parsedStmt.getStatementType() == StatementType.INSERT));

jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/BaseSqlParserFacadeTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,28 @@ public static Object[][] testCTEStmtsDP() {
239239
public void testMiscStatements(String sql, int args) {
240240
ParsedPreparedStatement stmt = parser.parsePreparedStatement(sql);
241241
Assert.assertEquals(stmt.getArgCount(), args);
242-
Assert.assertFalse(stmt.isHasErrors());
242+
Assert.assertFalse(stmt.isHasErrors(), "Statement has errors");
243243
}
244244

245245
@DataProvider
246246
public Object[][] testMiscStmtDp() {
247247
return new Object[][] {
248+
{"SELECT x, a FROM (SELECT arrayJoin(['Hello', 'Goodbye']) AS x, [1, 2, 3] AS arr) ARRAY JOIN arr AS a", 0},
249+
{"SELECT quantilesTiming(0.1, 0.5, 0.9)(dummy) FROM remote('127.0.0.{2,3}', 'system', 'one') GROUP BY 1 WITH TOTALS", 0}, // FROM remote issue
250+
{"SELECT StartDate, sumMerge(Visits) AS Visits, uniqMerge(Users) AS Users FROM basic_00040 GROUP BY StartDate ORDER BY StartDate", 0}, // keywords
251+
{"SELECT uniq(URL) FROM test.hits WHERE TraficSourceID IN (7)", 0}, // keywords URL
248252
{"SELECT INTERVAL '1 day'", 0},
249253
{"SELECT INTERVAL 1 day", 0},
254+
{"SET extremes = 1", 0},
255+
{"CREATE TABLE check_query_log (N UInt32,S String) Engine = Log", 0 },
256+
{"CREATE TABLE log (x UInt8) ENGINE = StripeLog", 0},
257+
{"CREATE TABLE check_query_log (N UInt32,S String) Engine = MergeTree", 0 },
258+
{"CREATE TABLE check_query_log (N UInt32,S String) Engine = ReplacingMergeTree", 0 },
259+
{"select abs(log(e()) - 1) < 1e-8", 0},
260+
{"SELECT SearchEngineID, ClientIP, count() AS c, sum(Refresh), avg(ResolutionWidth) " +
261+
" FROM test.hits_s3 WHERE SearchPhrase != '' GROUP BY SearchEngineID, ClientIP " +
262+
" ORDER BY c DESC LIMIT 10", 0},
263+
{"SELECT (id % 10) AS key, count() FROM 03279_test_database.test_table_1 GROUP BY key ORDER BY key", 0},
250264
{"SELECT ?", 1},
251265
{"(SELECT ?)", 1},
252266
{"SELECT * FROM table key WHERE ts = ?", 1},

0 commit comments

Comments
 (0)