From 3a42a6911369ffb9a894019950a8e8ec5ffa89bf Mon Sep 17 00:00:00 2001 From: Chen22 Date: Mon, 13 Dec 2021 14:14:40 -0800 Subject: [PATCH] feat: support show variables --- zetasql/parser/bison_parser.y | 14 ++++++++++++++ zetasql/parser/flex_tokenizer.l | 3 +++ zetasql/parser/keywords.cc | 3 +++ zetasql/parser/testdata/show.test | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/zetasql/parser/bison_parser.y b/zetasql/parser/bison_parser.y index 46cc0b0fd..053251d54 100644 --- a/zetasql/parser/bison_parser.y +++ b/zetasql/parser/bison_parser.y @@ -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" @@ -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" @@ -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" @@ -3566,6 +3569,14 @@ show_target: { $$ = parser->MakeIdentifier(@$, "PROCEDURE STATUS"); } + | "GLOBAL" "VARIABLES" + { + $$ = parser->MakeIdentifier(@$, "GLOBAL VARIABLES"); + } + | "SESSION" "VARIABLES" + { + $$ = parser->MakeIdentifier(@$, "SESSION VARIABLES"); + } | identifier { $$ = $1; @@ -7390,6 +7401,7 @@ keyword_as_identifier: | "FORMAT" | "FUNCTION" | "GENERATED" + | "GLOBAL" | "GRANT" | "GROUP_ROWS" | "HIDDEN" @@ -7455,6 +7467,7 @@ keyword_as_identifier: | "SCHEMA" | "SEARCH" | "SECURITY" + | "SESSION" | "SHOW" | "SIMPLE" | "SOURCE" @@ -7484,6 +7497,7 @@ keyword_as_identifier: | "USE" | "VALUE" | "VALUES" + | "VARIABLES" | "VIEW" | "VIEWS" | "VOLATILE" diff --git a/zetasql/parser/flex_tokenizer.l b/zetasql/parser/flex_tokenizer.l index c9cfc31b5..ecb741abd 100644 --- a/zetasql/parser/flex_tokenizer.l +++ b/zetasql/parser/flex_tokenizer.l @@ -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; } @@ -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; } @@ -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; } diff --git a/zetasql/parser/keywords.cc b/zetasql/parser/keywords.cc index d32cda9b5..5176f592b 100644 --- a/zetasql/parser/keywords.cc +++ b/zetasql/parser/keywords.cc @@ -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}, @@ -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}, @@ -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}, diff --git a/zetasql/parser/testdata/show.test b/zetasql/parser/testdata/show.test index 72434c5e8..c0c505b5a 100644 --- a/zetasql/parser/testdata/show.test +++ b/zetasql/parser/testdata/show.test @@ -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] @@ -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]