Skip to content

Commit

Permalink
Merge pull request google#31 from jingchen2222/feat/support_show_glob…
Browse files Browse the repository at this point in the history
…al_session_variables

feat: support show variables
  • Loading branch information
jingchen2222 authored Dec 14, 2021
2 parents b28a6ef + 3a42a69 commit 8dde6d0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions zetasql/parser/bison_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ using zetasql::ASTDropStatement;
%token KW_FORMAT "FORMAT"
%token KW_FUNCTION "FUNCTION"
%token KW_GENERATED "GENERATED"
%token KW_GLOBAL "GLOBAL"
%token KW_GRANT "GRANT"
%token KW_GROUP_ROWS "GROUP_ROWS"
%token KW_HIDDEN "HIDDEN"
Expand Down Expand Up @@ -905,6 +906,7 @@ using zetasql::ASTDropStatement;
%token KW_SCHEMA "SCHEMA"
%token KW_SEARCH "SEARCH"
%token KW_SECURITY "SECURITY"
%token KW_SESSION "SESSION"
%token KW_SHOW "SHOW"
%token KW_SIMPLE "SIMPLE"
%token KW_SOURCE "SOURCE"
Expand Down Expand Up @@ -934,6 +936,7 @@ using zetasql::ASTDropStatement;
%token KW_USE "USE"
%token KW_VALUE "VALUE"
%token KW_VALUES "VALUES"
%token KW_VARIABLES "VARIABLES"
%token KW_VOLATILE "VOLATILE"
%token KW_VIEW "VIEW"
%token KW_VIEWS "VIEWS"
Expand Down Expand Up @@ -3566,6 +3569,14 @@ show_target:
{
$$ = parser->MakeIdentifier(@$, "PROCEDURE STATUS");
}
| "GLOBAL" "VARIABLES"
{
$$ = parser->MakeIdentifier(@$, "GLOBAL VARIABLES");
}
| "SESSION" "VARIABLES"
{
$$ = parser->MakeIdentifier(@$, "SESSION VARIABLES");
}
| identifier
{
$$ = $1;
Expand Down Expand Up @@ -7390,6 +7401,7 @@ keyword_as_identifier:
| "FORMAT"
| "FUNCTION"
| "GENERATED"
| "GLOBAL"
| "GRANT"
| "GROUP_ROWS"
| "HIDDEN"
Expand Down Expand Up @@ -7455,6 +7467,7 @@ keyword_as_identifier:
| "SCHEMA"
| "SEARCH"
| "SECURITY"
| "SESSION"
| "SHOW"
| "SIMPLE"
| "SOURCE"
Expand Down Expand Up @@ -7484,6 +7497,7 @@ keyword_as_identifier:
| "USE"
| "VALUE"
| "VALUES"
| "VARIABLES"
| "VIEW"
| "VIEWS"
| "VOLATILE"
Expand Down
3 changes: 3 additions & 0 deletions zetasql/parser/flex_tokenizer.l
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ from { return BisonParserImpl::token::KW_FROM; }
full { return BisonParserImpl::token::KW_FULL; }
function { return BisonParserImpl::token::KW_FUNCTION; }
generated { return BisonParserImpl::token::KW_GENERATED; }
global { return BisonParserImpl::token::KW_GLOBAL; }
grant { return BisonParserImpl::token::KW_GRANT; }
group { return BisonParserImpl::token::KW_GROUP; }
group_rows { return BisonParserImpl::token::KW_GROUP_ROWS; }
Expand Down Expand Up @@ -603,6 +604,7 @@ safe_cast { return BisonParserImpl::token::KW_SAFE_CAST; }
schema { return BisonParserImpl::token::KW_SCHEMA; }
search { return BisonParserImpl::token::KW_SEARCH; }
security { return BisonParserImpl::token::KW_SECURITY; }
session { return BisonParserImpl::token::KW_SESSION; }
select { return BisonParserImpl::token::KW_SELECT; }
set { return BisonParserImpl::token::KW_SET; }
show { return BisonParserImpl::token::KW_SHOW; }
Expand Down Expand Up @@ -646,6 +648,7 @@ use { return BisonParserImpl::token::KW_USE; }
using { return BisonParserImpl::token::KW_USING; }
value { return BisonParserImpl::token::KW_VALUE; }
values { return BisonParserImpl::token::KW_VALUES; }
variables { return BisonParserImpl::token::KW_VARIABLES; }
view { return BisonParserImpl::token::KW_VIEW; }
views { return BisonParserImpl::token::KW_VIEWS; }
volatile { return BisonParserImpl::token::KW_VOLATILE; }
Expand Down
3 changes: 3 additions & 0 deletions zetasql/parser/keywords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"full", KW_FULL, KeywordInfo::kReserved},
{"function", KW_FUNCTION},
{"generated", KW_GENERATED},
{"global", KW_GLOBAL},
{"grant", KW_GRANT},
{"group", KW_GROUP, KeywordInfo::kReserved},
{"group_rows", KW_GROUP_ROWS},
Expand Down Expand Up @@ -261,6 +262,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"search", KW_SEARCH},
{"security", KW_SECURITY},
{"select", KW_SELECT, KeywordInfo::kReserved},
{"session", KW_SESSION},
{"set", KW_SET, KeywordInfo::kReserved},
{"show", KW_SHOW},
{"simple", KW_SIMPLE},
Expand Down Expand Up @@ -301,6 +303,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"using", KW_USING, KeywordInfo::kReserved},
{"value", KW_VALUE},
{"values", KW_VALUES},
{"variables", KW_VARIABLES},
{"volatile", KW_VOLATILE},
{"view", KW_VIEW},
{"views", KW_VIEWS},
Expand Down
24 changes: 24 additions & 0 deletions zetasql/parser/testdata/show.test
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ ShowStatement [0-9]
SHOW JOBS
==

show VARIABLES;
--
ShowStatement [0-14]
Identifier(VARIABLES) [5-14]
--
SHOW VARIABLES
==

show VARIABLES like 'server_name';
--
ShowStatement [0-33]
Expand All @@ -135,6 +143,22 @@ ShowStatement [0-33]
SHOW VARIABLES LIKE 'server_name'
==

show GLOBAL VARIABLES;
--
ShowStatement [0-21]
Identifier(`GLOBAL VARIABLES`) [5-21]
--
SHOW `GLOBAL VARIABLES`
==

show SESSION VARIABLES;
--
ShowStatement [0-22]
Identifier(`SESSION VARIABLES`) [5-22]
--
SHOW `SESSION VARIABLES`
==

show TABLES from adwords like b'abc%';
--
ERROR: Syntax error: Expected string literal but got bytes literal b'abc%' [at 1:31]
Expand Down

0 comments on commit 8dde6d0

Please sign in to comment.