Skip to content

Commit

Permalink
feat: add flush privileges support
Browse files Browse the repository at this point in the history
  • Loading branch information
oh2024 committed May 28, 2024
1 parent 18146d1 commit 6adaf8d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions zetasql/parser/bison_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ using zetasql::ASTDropStatement;
%token KW_SECURITY "SECURITY"
%token KW_SESSION "SESSION"
%token KW_SHOW "SHOW"
%token KW_FLUSH "FLUSH"
%token KW_SIMPLE "SIMPLE"
%token KW_SOURCE "SOURCE"
%token KW_SQL "SQL"
Expand Down Expand Up @@ -1302,6 +1303,7 @@ using zetasql::ASTDropStatement;
%type <node> select_list
%type <node> select_list_prefix
%type <node> show_statement
%type <node> flush_statement
%type <node> target_name
%type <identifier> show_target
%type <identifier> show_with_name_target
Expand Down Expand Up @@ -1621,6 +1623,7 @@ sql_statement_body:
| show_statement
| drop_all_row_access_policies_statement
| drop_statement
| flush_statement
| call_statement
| import_statement
| module_statement
Expand Down Expand Up @@ -3721,6 +3724,14 @@ show_statement:
}
;

flush_statement:
"FLUSH" "PRIVILEGES"
{
$$ = MAKE_NODE(ASTFlushStatement, @$, {"PRIVILEGES"});
}
;


show_target:
"MATERIALIZED" "VIEWS"
{
Expand Down
1 change: 1 addition & 0 deletions zetasql/parser/flex_tokenizer.l
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ fill { return BisonParserImpl::token::KW_FILL; }
filter { return BisonParserImpl::token::KW_FILTER; }
filter_fields { return BisonParserImpl::token::KW_FILTER_FIELDS; }
first { return BisonParserImpl::token::KW_FIRST; }
flush { return BisonParserImpl::token::KW_FLUSH; }
following { return BisonParserImpl::token::KW_FOLLOWING; }
for { return BisonParserImpl::token::KW_FOR; }
foreign { return BisonParserImpl::token::KW_FOREIGN; }
Expand Down
1 change: 1 addition & 0 deletions zetasql/parser/keywords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"filter_fields", KW_FILTER_FIELDS},
{"fill", KW_FILL},
{"first", KW_FIRST},
{"flush", KW_FLUSH},
{"following", KW_FOLLOWING, KeywordInfo::kReserved},
{"for", KW_FOR, KeywordInfo::kReserved},
{"foreign", KW_FOREIGN},
Expand Down
35 changes: 35 additions & 0 deletions zetasql/parser/testdata/flush_privileges.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
flush privileges;
--
FlushStatement [0-16]
Keyword(`PRIVILEGES`) [6-16]
--
FLUSH PRIVILEGES
==

flush privileges with extra;
--
ERROR: Syntax error: Expected end of input but got identifier "with" [at 1:19]
flush privileges with extra;
^
==

flush privileges like;
--
ERROR: Syntax error: Expected end of input but got identifier "like" [at 1:18]
flush privileges like;
^
==

flush;
--
ERROR: Syntax error: Expected "PRIVILEGES" but got ";" [at 1:6]
flush;
^
==

flush something else;
--
ERROR: Syntax error: Expected "PRIVILEGES" but got "something" [at 1:7]
flush something else;
^
==

0 comments on commit 6adaf8d

Please sign in to comment.