Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d1703cc
fixes CTE parsing issue and using table as alias
chernser Sep 10, 2025
1f30b73
Merge branch 'main' into jdbc_fix_cte_parse
chernser Sep 25, 2025
e9fe471
Merge branch 'main' into jdbc_fix_cte_parse
chernser Sep 28, 2025
9f4aa7a
Added more tests
chernser Oct 1, 2025
2113b87
filled test statements
chernser Oct 3, 2025
3a96804
moved parser to separate package to track coverage
chernser Oct 3, 2025
25cca50
fixed show statement tests
chernser Oct 6, 2025
6f7e415
Fixed statements with result set and several other
chernser Oct 7, 2025
b2d2399
fixed GRANT stmts and added REVOKE statements
chernser Oct 7, 2025
dfc938c
fixed more statement tests
chernser Oct 7, 2025
aefc7c9
added MOVE and UNDROP statements
chernser Oct 7, 2025
4efa2c1
Fixed quota statements
chernser Oct 7, 2025
25549e7
Fixed insert statements
chernser Oct 7, 2025
f9dd217
Fixed CTE and some minor bugs
chernser Oct 9, 2025
8db01eb
fixed CTE arguments positioning and fixed add column expression
chernser Oct 14, 2025
07eac76
fixed more statements
chernser Oct 14, 2025
0f04adf
fixed column position in alter statement and renamed QUERY to JDBC_PA…
chernser Oct 15, 2025
3e18522
created a SQL parser facade to implement SQL parser selection
chernser Oct 16, 2025
9cb7738
implemented antlr4 two variants
chernser Oct 17, 2025
0cbf958
Fixed issue with # comments
chernser Oct 17, 2025
505272d
Added javaCC parser implementation. not a default. some tests failing
chernser Oct 20, 2025
fdfc35b
Fixed javacc to support single line comments and some new statements
chernser Oct 22, 2025
f02382f
Fixed some keyword issues
chernser Oct 24, 2025
6372e4e
Fixed some more antlr4 issues
chernser Oct 25, 2025
cf863d4
Merge branch 'main' into jdbc_fix_cte_parse
chernser Oct 27, 2025
4f45dc8
Added a few SQL tests fro Statement/PreparedStatement. Addded more te…
chernser Oct 27, 2025
b930ca2
Fixed javaCC for set roles statements and getting correct table name
chernser Oct 27, 2025
24c8e81
Added new statements to javacc. fixed some existing statements
chernser Oct 27, 2025
5f172d2
fixed alter table - type is not required.
chernser Oct 27, 2025
967e7dc
added tests with lambda
chernser Oct 28, 2025
8b2406e
fixed ANTLR4 for expressions with IP keyword
chernser Oct 29, 2025
2b108b0
fixed in statement with multiple arguments
chernser Oct 29, 2025
b773b7e
fixed problem with detecting function in insert statement
chernser Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed CTE arguments positioning and fixed add column expression
  • Loading branch information
chernser committed Oct 14, 2025
commit 8db01eb625d96e4fa7c8f1db810fcf7f3943739a
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ alterStmt
;

alterTableClause
: ADD COLUMN (IF NOT EXISTS)? tableColumnDfnt (AFTER (nestedIdentifier | FIRST))? # AlterTableClauseAddColumn
| ADD INDEX (IF NOT EXISTS)? tableIndexDfnt (AFTER (nestedIdentifier | FIRST))? # AlterTableClauseAddIndex
: ADD COLUMN (IF NOT EXISTS)? tableColumnDfnt ((AFTER nestedIdentifier) | FIRST)? # AlterTableClauseAddColumn
| ADD INDEX (IF NOT EXISTS)? tableIndexDfnt ((AFTER nestedIdentifier) | FIRST)? # AlterTableClauseAddIndex
| ADD PROJECTION (IF NOT EXISTS)? tableProjectionDfnt (AFTER (nestedIdentifier | FIRST))? # AlterTableClauseAddProjection

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

((AFTER nestedIdentifier) | FIRST)?

| ATTACH partitionClause (FROM tableIdentifier)? # AlterTableClauseAttach
| CLEAR COLUMN (IF EXISTS)? nestedIdentifier (IN partitionClause)? # AlterTableClauseClearColumn
Expand All @@ -84,7 +84,7 @@ alterTableClause
| MODIFY COLUMN (IF EXISTS)? nestedIdentifier COMMENT STRING_LITERAL # AlterTableClauseModifyComment
| MODIFY COLUMN (IF EXISTS)? nestedIdentifier REMOVE tableColumnPropertyType # AlterTableClauseModifyRemove
| MODIFY COLUMN (IF EXISTS)? tableColumnDfnt # AlterTableClauseModify
| ALTER COLUMN (IF EXISTS)? identifier TYPE columnTypeExpr codecExpr? ttlClause? settingExprList? (AFTER (nestedIdentifier | FIRST))? # AlterTableClauseAlterType
| ALTER COLUMN (IF EXISTS)? identifier TYPE columnTypeExpr codecExpr? ttlClause? settingExprList? ((AFTER nestedIdentifier) | FIRST)? # AlterTableClauseAlterType
| MODIFY ORDER BY columnExpr # AlterTableClauseModifyOrderBy
| MODIFY ttlClause # AlterTableClauseModifyTTL
| MODIFY COMMENT literal # AlterTableClauseModifyComment
Expand Down Expand Up @@ -471,7 +471,7 @@ withClause

// CTE statement
cteClause
: WITH cteUnboundCol? (COMMA cteUnboundCol)* COMMA? namedQuery? (COMMA namedQuery)*
: WITH (cteUnboundCol | namedQuery) (COMMA (cteUnboundCol | namedQuery))*
;


Expand All @@ -487,6 +487,7 @@ cteUnboundCol
: literal AS identifier # CteUnboundColLiteral
| QUERY AS identifier # CteUnboundColParam
| LPAREN? columnExpr RPAREN? AS? identifier? # CteUnboundColExpr
| LPAREN selectStmt RPAREN AS identifier # CteUnboundSubQuery
// | LPAREN cteStmt? selectStmt RPAREN AS identifier # CteUnboundNestedSelect
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ public static Object[][] testCreateStmtDP() {

@Test(dataProvider = "testCTEStmtsDP")
public void testCTEStatements(String sql, int args) {
System.out.println(sql);
SqlParser parser = new SqlParser();
ParsedPreparedStatement stmt = parser.parsePreparedStatement(sql);
Assert.assertEquals(stmt.getArgCount(), args, "Args mismatch");
Expand Down Expand Up @@ -269,6 +268,13 @@ public static Object[][] testCTEStmtsDP() {
{COMPLEX_CTE, 4},
{"WITH 'date' as const1, 'time' as const2, Tmp1 as (SELECT 1), Tmp2 as (SELECT * FROM Tmp1) SELECT * FROM Tmp2 ", 0},
{"WITH query1 AS ( WITH 'a' as date1 SELECT * FROM tracking.event WHERE project='a' AND time>=starting_time AND time<ending_time GROUP BY date, user_id ) SELECT * FROM query1", 0},
{"WITH a AS (SELECT ?), (SELECT 2) AS b SELECT b, *, c FROM a", 1},
{"WITH a AS (SELECT ?), (SELECT 2) AS b, c as (SELECT ?) SELECT *, b FROM a, c", 2},
{"WITH (SELECT 2) AS b, a as (select ?), (select 3) AS c SELECT *, b, c FROM a", 1},
{"WITH a AS (SELECT 2), (WITH 'a' as b1 SELECT 3, b1) AS b SELECT b, * FROM a", 0},
{"WITH a AS (SELECT ?), (WITH ? as b1 SELECT 3, b1) AS b SELECT b, * FROM a", 2},
{"WITH a AS (SELECT 2), (WITH 'a' as b1 SELECT 3, b1) AS b, c AS (SELECT 4) SELECT b, * FROM a, c", 0},

};
}

Expand All @@ -285,6 +291,8 @@ public Object[][] testMiscStmtDp() {
return new Object[][] {
{"SELECT INTERVAL '1 day'", 0},
{"SELECT INTERVAL 1 day", 0},
{"SELECT ?", 1},
{"(SELECT ?)", 1},
{"SELECT * FROM table key WHERE ts = ?", 1},
{"SELECT * FROM table source WHERE ts = ?", 1},
{"SELECT * FROM table after WHERE ts = ?", 1},
Expand Down Expand Up @@ -540,7 +548,7 @@ public static Object[][] testStatementWithoutResultSetDP() {
{"CREATE VIEW `test_db`.`source_table` source AS ( SELECT * FROM source_a UNION SELECT * FROM source_b) ENGINE = MaterializedView", 0, false},
{"CREATE VIEW `test_db`.`source_table` source AS ( SELECT * FROM source_a UNION SELECT * FROM source_b) ENGINE = MaterializedView()", 0, false},
{"CREATE VIEW `test_db`.`source_table` source AS ( SELECT * FROM source_a UNION SELECT * FROM source_b) ENGINE = MaterializedView() COMMENT 'for tests'", 0, false},
{ "CREATE DICTIONARY `test_db`.dict1 (k1 UInt64 EXPRESSION(k1 + 1), k2 String DEFAULT 'default', a1 Array(UInt64) DEFAULT []) PRIMARY KEY k1 SOURCE(CLICKHOUSE(db='test_db', table='dict1')) LAYOUT(FLAT()) LIFETIME(MIN 1000 MAX 2000)", 0, false},
{"CREATE DICTIONARY `test_db`.dict1 (k1 UInt64 EXPRESSION(k1 + 1), k2 String DEFAULT 'default', a1 Array(UInt64) DEFAULT []) PRIMARY KEY k1 SOURCE(CLICKHOUSE(db='test_db', table='dict1')) LAYOUT(FLAT()) LIFETIME(MIN 1000 MAX 2000)", 0, false},
{"CREATE DICTIONARY `test_db`.dict1 (k1 UInt64 (k1 + 1), k2 String DEFAULT 'default', a1 Array(UInt64) DEFAULT []) PRIMARY KEY k1 SOURCE(CLICKHOUSE(db='test_db', table='dict1')) LAYOUT(FLAT()) LIFETIME(MIN 1000 MAX 2000) SETTINGS(cache_size = 1000) COMMENT 'for tests'", 0, false},
{"CREATE OR REPLACE DICTIONARY IF NOT EXISTS `test_db`.dict1 (k1 UInt64 (k1 + 1), k2 String DEFAULT 'default', a1 Array(UInt64) DEFAULT []) PRIMARY KEY k1 SOURCE(CLICKHOUSE(db='test_db', table='dict1')) LAYOUT(FLAT()) LIFETIME(MIN 1000 MAX 2000) SETTINGS(cache_size = 1000, v='123') COMMENT 'for tests'", 0, false},
{"CREATE FUNCTION test_func AS () -> 10", 0, false},
Expand All @@ -562,11 +570,12 @@ public static Object[][] testStatementWithoutResultSetDP() {
{"alter table t2 alter column v type Int32", 0, false},
{"ALTER TABLE t MODIFY COLUMN j default 1", 0, false},
{"ALTER TABLE t MODIFY COMMENT 'comment'", 0, false},
{"ALTER TABLE t ADD COLUMN id Int32 AFTER v", 0, false},
{"ALTER TABLE t ADD COLUMN id Int32 FIRST", 0, false},
{"DELETE FROM db.table1 ON CLUSTER `default` WHERE max(a, 10) > ?", 1, false},
{"DELETE FROM table WHERE a = ?", 1, false},
{"DELETE FROM table WHERE a = ? AND b = ?", 2, false},
{"DELETE FROM hits WHERE Title LIKE '%hello%';", 0, false},

{"SYSTEM START FETCHES", 0, false},
{"SYSTEM RELOAD DICTIONARIES", 0, false},
{"SYSTEM RELOAD DICTIONARIES ON CLUSTER `default`", 0, false},
Expand Down
Loading