diff --git a/parser/ast.go b/parser/ast.go index 750d8e8..4f5ec64 100644 --- a/parser/ast.go +++ b/parser/ast.go @@ -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() } diff --git a/parser/parse_system.go b/parser/parse_system.go index fd5605c..f02cb2b 100644 --- a/parser/parse_system.go +++ b/parser/parse_system.go @@ -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 diff --git a/parser/testdata/ddl/format/grant_privilege.sql b/parser/testdata/ddl/format/grant_privilege.sql index ead60c3..3dc89d7 100644 --- a/parser/testdata/ddl/format/grant_privilege.sql +++ b/parser/testdata/ddl/format/grant_privilege.sql @@ -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: @@ -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; diff --git a/parser/testdata/ddl/grant_privilege.sql b/parser/testdata/ddl/grant_privilege.sql index 1efb19a..c11772c 100644 --- a/parser/testdata/ddl/grant_privilege.sql +++ b/parser/testdata/ddl/grant_privilege.sql @@ -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; diff --git a/parser/testdata/ddl/output/grant_privilege.sql.golden.json b/parser/testdata/ddl/output/grant_privilege.sql.golden.json index def3834..4d3d4d5 100644 --- a/parser/testdata/ddl/output/grant_privilege.sql.golden.json +++ b/parser/testdata/ddl/output/grant_privilege.sql.golden.json @@ -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" + ] } ] \ No newline at end of file