Skip to content

Commit 81bf403

Browse files
committed
bug(query): fix grant create user err
1 parent c2b403d commit 81bf403

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

src/meta/app/src/principal/user_privilege.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum UserPrivilegeType {
4646
Create = 1 << 1,
4747
// Privilege to drop databases or tables.
4848
Drop = 1 << 7,
49-
// Privilege to delete rows in a table
49+
// Privilege to alter databases or tables.
5050
Alter = 1 << 8,
5151
// Privilege to Kill query, Set global configs, etc.
5252
Super = 1 << 9,

src/query/ast/src/parser/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,6 @@ pub fn priv_type(i: Input) -> IResult<UserPrivilegeType> {
13591359
value(UserPrivilegeType::Insert, rule! { INSERT }),
13601360
value(UserPrivilegeType::Update, rule! { UPDATE }),
13611361
value(UserPrivilegeType::Delete, rule! { DELETE }),
1362-
value(UserPrivilegeType::Create, rule! { CREATE }),
13631362
value(UserPrivilegeType::Drop, rule! { DROP }),
13641363
value(UserPrivilegeType::Alter, rule! { ALTER }),
13651364
value(UserPrivilegeType::Super, rule! { SUPER }),
@@ -1368,6 +1367,7 @@ pub fn priv_type(i: Input) -> IResult<UserPrivilegeType> {
13681367
value(UserPrivilegeType::Grant, rule! { GRANT }),
13691368
value(UserPrivilegeType::CreateStage, rule! { CREATE ~ STAGE }),
13701369
value(UserPrivilegeType::Set, rule! { SET }),
1370+
value(UserPrivilegeType::Create, rule! { CREATE }),
13711371
))(i)
13721372
}
13731373

src/query/ast/tests/it/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ fn test_statement() {
167167
r#"ALTER DATABASE c RENAME TO a;"#,
168168
r#"ALTER DATABASE ctl.c RENAME TO a;"#,
169169
r#"CREATE TABLE t (a INT COMMENT 'col comment') COMMENT='table comment';"#,
170+
r#"GRANT CREATE, CREATE USER ON * TO 'test-grant'@'localhost';"#,
170171
r#"GRANT SELECT, CREATE ON * TO 'test-grant'@'localhost';"#,
171172
r#"GRANT SELECT, CREATE ON *.* TO 'test-grant'@'localhost';"#,
172173
r#"GRANT SELECT, CREATE ON * TO USER 'test-grant'@'localhost';"#,

src/query/ast/tests/it/testdata/statement-error.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ error:
233233
--> SQL:1:15
234234
|
235235
1 | GRANT SELECT, ALL PRIVILEGES, CREATE ON * TO 'test-grant'@'localhost';
236-
| ----- ------ ^^^ expected `USAGE`, `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `CREATE`, or 5 more ...
236+
| ----- ------ ^^^ expected `USAGE`, `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `DROP`, or 5 more ...
237237
| | |
238238
| | while parsing <privileges> ON <privileges_level>
239239
| while parsing `GRANT { ROLE <role_name> | schemaObjectPrivileges | ALL [ PRIVILEGES ] ON <privileges_level> } TO { [ROLE <role_name>] | [USER] <user> }`
@@ -268,7 +268,7 @@ error:
268268
--> SQL:1:24
269269
|
270270
1 | REVOKE SELECT, CREATE, ALL PRIVILEGES ON * FROM 'test-grant'@'localhost';
271-
| ------ ------ ^^^ expected `USAGE`, `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `CREATE`, or 5 more ...
271+
| ------ ------ ^^^ expected `USAGE`, `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `DROP`, or 5 more ...
272272
| | |
273273
| | while parsing <privileges> ON <privileges_level>
274274
| while parsing `REVOKE { ROLE <role_name> | schemaObjectPrivileges | ALL [ PRIVILEGES ] ON <privileges_level> } FROM { [ROLE <role_name>] | [USER] <user> }`

src/query/ast/tests/it/testdata/statement.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6167,6 +6167,32 @@ CreateTable(
61676167
)
61686168

61696169

6170+
---------- Input ----------
6171+
GRANT CREATE, CREATE USER ON * TO 'test-grant'@'localhost';
6172+
---------- Output ---------
6173+
GRANT CREATE, CREATE USER ON * TO USER 'test-grant'@'localhost'
6174+
---------- AST ------------
6175+
Grant(
6176+
GrantStmt {
6177+
source: Privs {
6178+
privileges: [
6179+
Create,
6180+
CreateUser,
6181+
],
6182+
level: Database(
6183+
None,
6184+
),
6185+
},
6186+
principal: User(
6187+
UserIdentity {
6188+
username: "test-grant",
6189+
hostname: "localhost",
6190+
},
6191+
),
6192+
},
6193+
)
6194+
6195+
61706196
---------- Input ----------
61716197
GRANT SELECT, CREATE ON * TO 'test-grant'@'localhost';
61726198
---------- Output ---------

0 commit comments

Comments
 (0)