Skip to content

Commit b2d2399

Browse files
committed
fixed GRANT stmts and added REVOKE statements
1 parent 6f7e415 commit b2d2399

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ PROFILE : P R O F I L E;
237237
PROFILES : P R O F I L E S;
238238
PROJECTION : P R O J E C T I O N;
239239
PULLING : P U L L I N G ;
240+
REVOKE : R E V O K E;
240241
QUARTER : Q U A R T E R;
241242
QUEUE : Q U E U E ;
242243
QUEUES : Q U E U E S ;

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ query
3333
| showStmt
3434
| systemStmt
3535
| truncateStmt // DDL
36+
| deleteStmt
37+
| updateStmt
3638
| useStmt
3739
| watchStmt
3840
| ctes? selectStmt
3941
| grantStmt
42+
| revokeStmt
4043
;
4144

4245
// CTE statement
@@ -59,16 +62,27 @@ cteUnboundCol
5962
| LPAREN ctes? selectStmt RPAREN AS identifier # CteUnboundNestedSelect
6063
;
6164

65+
// DELETE statement
66+
67+
deleteStmt
68+
: DELETE FROM tableIdentifier clusterClause? (IN partitionClause)? whereClause?
69+
;
70+
71+
// UPDATE statement
72+
updateStmt
73+
: UPDATE tableIdentifier clusterClause? SET assignmentExprList whereClause?
74+
;
75+
6276
// ALTER statement
6377

6478
alterStmt
6579
: ALTER TABLE tableIdentifier clusterClause? alterTableClause (COMMA alterTableClause)* # AlterTableStmt
6680
;
6781

6882
alterTableClause
69-
: ADD COLUMN (IF NOT EXISTS)? tableColumnDfnt (AFTER nestedIdentifier)? # AlterTableClauseAddColumn
70-
| ADD INDEX (IF NOT EXISTS)? tableIndexDfnt (AFTER nestedIdentifier)? # AlterTableClauseAddIndex
71-
| ADD PROJECTION (IF NOT EXISTS)? tableProjectionDfnt (AFTER nestedIdentifier)? # AlterTableClauseAddProjection
83+
: ADD COLUMN (IF NOT EXISTS)? tableColumnDfnt (AFTER (nestedIdentifier | FIRST))? # AlterTableClauseAddColumn
84+
| ADD INDEX (IF NOT EXISTS)? tableIndexDfnt (AFTER (nestedIdentifier | FIRST))? # AlterTableClauseAddIndex
85+
| ADD PROJECTION (IF NOT EXISTS)? tableProjectionDfnt (AFTER (nestedIdentifier | FIRST))? # AlterTableClauseAddProjection
7286
| ATTACH partitionClause (FROM tableIdentifier)? # AlterTableClauseAttach
7387
| CLEAR COLUMN (IF EXISTS)? nestedIdentifier (IN partitionClause)? # AlterTableClauseClearColumn
7488
| CLEAR INDEX (IF EXISTS)? nestedIdentifier (IN partitionClause)? # AlterTableClauseClearIndex
@@ -87,6 +101,7 @@ alterTableClause
87101
| MODIFY COLUMN (IF EXISTS)? nestedIdentifier COMMENT STRING_LITERAL # AlterTableClauseModifyComment
88102
| MODIFY COLUMN (IF EXISTS)? nestedIdentifier REMOVE tableColumnPropertyType # AlterTableClauseModifyRemove
89103
| MODIFY COLUMN (IF EXISTS)? tableColumnDfnt # AlterTableClauseModify
104+
| ALTER COLUMN (IF EXISTS)? identifier TYPE columnTypeExpr codecExpr? ttlClause? settingExprList? (AFTER (nestedIdentifier | FIRST))? # AlterTableClauseAlterType
90105
| MODIFY ORDER BY columnExpr # AlterTableClauseModifyOrderBy
91106
| MODIFY ttlClause # AlterTableClauseModifyTTL
92107
| MODIFY COMMENT literal # AlterTableClauseModifyComment
@@ -107,6 +122,7 @@ assignmentExprList
107122

108123
assignmentExpr
109124
: nestedIdentifier EQ_SINGLE columnExpr
125+
| nestedIdentifier EQ_SINGLE QUERY
110126
;
111127

112128
tableColumnPropertyType
@@ -608,10 +624,25 @@ setRolesList
608624
: identifier (COMMA identifier)*
609625
;
610626

627+
// GRANT statements
628+
611629
grantStmt
612-
: GRANT clusterClause? ((privilege ON grantTableIdentifier) | (identifier (COMMA identifier)*))
630+
: GRANT clusterClause? identifier (COMMA identifier)* TO (CURRENT_USER | identifier (COMMA identifier)*)
631+
(WITH ADMIN OPTION)? (WITH REPLACE OPTION)?
632+
| GRANT clusterClause? privelegeList ON grantTableIdentifier
613633
TO (CURRENT_USER | identifier) (COMMA identifier)*
614634
(WITH GRANT OPTION)? (WITH REPLACE OPTION)?
635+
| GRANT CURRENT GRANTS (LPAREN ((privelegeList ON grantTableIdentifier) | (identifier (COMMA identifier)*)) RPAREN)?
636+
TO (CURRENT_USER | identifier (COMMA identifier)*)
637+
(WITH GRANT OPTION)? (WITH REPLACE OPTION)?
638+
;
639+
640+
// REVOKE statements
641+
revokeStmt
642+
: REVOKE clusterClause? privelegeList ON grantTableIdentifier
643+
FROM ((CURRENT_USER | identifier) (COMMA identifier)* | ALL | ALL EXCEPT (CURRENT_USER | identifier) (COMMA identifier)* )
644+
| REVOKE clusterClause? (ADMIN OPTION FOR)? identifier (COMMA identifier)*
645+
FROM ((CURRENT_USER | identifier) (COMMA identifier)* | ALL | ALL EXCEPT (CURRENT_USER | identifier) (COMMA identifier)* )
615646
;
616647

617648
grantTableIdentifier
@@ -621,6 +652,15 @@ grantTableIdentifier
621652
| (ASTERISK DOT)? ASTERISK
622653
;
623654

655+
privelegeList
656+
: columnPrivilege (COMMA columnPrivilege)*
657+
;
658+
659+
660+
columnPrivilege
661+
: privilege (LPAREN identifier (COMMA identifier)* RPAREN)?
662+
;
663+
624664
privilege
625665
:
626666
| ACCESS MANAGEMENT

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ public static Object[][] testStatementWithoutResultSetDP() {
542542
{"CREATE QUOTA qB FOR INTERVAL 30 minute MAX execution_time = 0.5, FOR INTERVAL 5 quarter MAX queries = 321, errors = 10 TO default", 0, false},
543543
{"CREATE SETTINGS PROFILE max_memory_usage_profile SETTINGS max_memory_usage = 100000001 MIN 90000000 MAX 110000000 TO robin", 0, false},
544544
{"CREATE NAMED COLLECTION foobar AS a = '1', b = '2' OVERRIDABLE", 0, false},
545-
// {"alter table t alter column j default 1", 0, false}, // not supported by CH
545+
{"alter table t2 alter column v type Int32", 0, false},
546546
{"ALTER TABLE t MODIFY COLUMN j default 1", 0, false},
547547
{"ALTER TABLE t MODIFY COMMENT 'comment'", 0, false},
548548
{"DELETE FROM db.table1 ON CLUSTER `default` WHERE max(a, 10) > ?", 1, false},
@@ -555,10 +555,10 @@ public static Object[][] testStatementWithoutResultSetDP() {
555555
{"SYSTEM RELOAD DICTIONARIES ON CLUSTER `default`", 0, false},
556556
{"GRANT SELECT ON db.* TO john", 0, false},
557557
{"GRANT ON CLUSTER `default` SELECT(a, b) ON db1.tableA TO `user` WITH GRANT OPTION WITH REPLACE OPTION", 0, false},
558-
{"GRANT SELECT db.* TO user01 WITH REPLACE OPTION", 0, false},
558+
{"GRANT SELECT ON db.* TO user01 WITH REPLACE OPTION", 0, false},
559559
{"GRANT ON CLUSTER role1, role2 TO `user01` WITH ADMIN OPTION WITH REPLACE OPTION", 0, false},
560560
{"GRANT CURRENT GRANTS TO user01", 0, false},
561-
{"REVOKE SELECT(a,b) ON db1.tableA FROM `user01", 0, false},
561+
{"REVOKE SELECT(a,b) ON db1.tableA FROM `user01`", 0, false},
562562
{"REVOKE SELECT ON db1.* FROM ALL", 0, false},
563563
{"REVOKE SELECT ON db1.* FROM ALL EXCEPT `admin01`", 0, false},
564564
{"REVOKE SELECT ON db1.* FROM ALL EXCEPT CURRENT USER", 0, false},
@@ -606,6 +606,7 @@ public static Object[][] testStatementWithoutResultSetDP() {
606606
{"EXCHANGE DICTIONARIES dict1 AND dict2", 0, false},
607607
{"EXCHANGE DICTIONARIES dict1 AND dict2 ON CLUSTER `default`", 0, false},
608608
{"SET profile = 'profile-name-from-the-settings-file'", 0, false},
609+
{"SET use_some_feature_flag", 0, false},
609610
{"SET ROLE role1", 0, false},
610611
{"SET DEFAULT ROLE role1 TO user", 0, false},
611612
{"SET DEFAULT ROLE NONE TO user", 0, false},

0 commit comments

Comments
 (0)