Skip to content

Commit

Permalink
Allow to use GRANT ALL
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk committed Nov 3, 2023
1 parent 91f3ce2 commit 57ca48c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
4 changes: 3 additions & 1 deletion parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3960,7 +3960,9 @@ func (p *PrivilegeExpr) String(level int) string {
}
builder.WriteString(keyword)
}
builder.WriteString(p.Params.String(level))
if p.Params != nil {
builder.WriteString(p.Params.String(level))
}
return builder.String()
}

Expand Down
5 changes: 5 additions & 0 deletions parser/parse_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,11 @@ func (p *Parser) parsePrivilege(pos Pos) (*PrivilegeExpr, error) {
return p.parsePrivilegeDrop(pos)
case p.tryConsumeKeyword(KeywordShow) != nil:
return p.parsePrivilegeShow(pos)
case p.tryConsumeKeyword(KeywordAll) != nil:
return &PrivilegeExpr{
PrivilegePos: pos,
Keywords: []string{KeywordAll},
}, nil
case p.tryConsumeKeyword(KeywordKill) != nil:
if err := p.consumeKeyword(KeywordQuery); err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions parser/testdata/ddl/format/grant_privilege.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ GRANT SELECT(x,y) ON *.table TO john;
GRANT SELECT(x,y) ON *.* TO john;
GRANT SELECT(x,y) ON *.table TO CURRENT_USER;
GRANT SELECT(x,y) ON *.table TO CURRENT_USER,john,mary;
GRANT ALL ON *.* TO admin_role WITH GRANT OPTION;


-- Format SQL:
Expand All @@ -16,3 +17,4 @@ GRANT SELECT(x, y) ON *.table TO john;
GRANT SELECT(x, y) ON *.* TO john;
GRANT SELECT(x, y) ON *.table TO CURRENT_USER;
GRANT SELECT(x, y) ON *.table TO CURRENT_USER, john, mary;
GRANT ALL ON *.* TO admin_role WITH GRANT OPTION;
1 change: 1 addition & 0 deletions parser/testdata/ddl/grant_privilege.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ GRANT SELECT(x,y) ON *.table TO john;
GRANT SELECT(x,y) ON *.* TO john;
GRANT SELECT(x,y) ON *.table TO CURRENT_USER;
GRANT SELECT(x,y) ON *.table TO CURRENT_USER,john,mary;
GRANT ALL ON *.* TO admin_role WITH GRANT OPTION;
40 changes: 40 additions & 0 deletions parser/testdata/ddl/output/grant_privilege.sql.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,5 +440,45 @@
}
],
"WithOptions": []
},
{
"GrantPos": 323,
"StatementEnd": 372,
"OnCluster": null,
"Privileges": [
{
"PrivilegePos": 329,
"PrivilegeEnd": 0,
"Keywords": [
"ALL"
],
"Params": null
}
],
"On": {
"Database": {
"Name": "*",
"Unquoted": false,
"NamePos": 336,
"NameEnd": 337
},
"Table": {
"Name": "*",
"Unquoted": false,
"NamePos": 338,
"NameEnd": 339
}
},
"To": [
{
"Name": "admin_role",
"Unquoted": false,
"NamePos": 343,
"NameEnd": 353
}
],
"WithOptions": [
"GRANT"
]
}
]

0 comments on commit 57ca48c

Please sign in to comment.