From 495ab59aadf4b3a08ecd7643e0cb3c972f45507c Mon Sep 17 00:00:00 2001 From: Justin Joyce Date: Mon, 26 Sep 2022 07:33:53 +0100 Subject: [PATCH] Support `SHOW FUNCTIONS` (#620) * support SHOW FUNCTIONS * Update keywords.rs * Update mod.rs * Update sqlparser_common.rs * Fix CI issues --- src/ast/mod.rs | 11 +++++++++++ src/keywords.rs | 1 + src/parser.rs | 7 +++++++ tests/sqlparser_common.rs | 10 ++++++++++ 4 files changed, 29 insertions(+) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 6c279518..a6654be0 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -1144,6 +1144,10 @@ pub enum Statement { /// /// Note: this is a MySQL-specific statement. SetNamesDefault {}, + /// SHOW FUNCTIONS + /// + /// Note: this is a Presto-specific statement. + ShowFunctions { filter: Option }, /// SHOW /// /// Note: this is a PostgreSQL-specific statement. @@ -2033,6 +2037,13 @@ impl fmt::Display for Statement { } Ok(()) } + Statement::ShowFunctions { filter } => { + write!(f, "SHOW FUNCTIONS")?; + if let Some(filter) = filter { + write!(f, " {}", filter)?; + } + Ok(()) + } Statement::Use { db_name } => { write!(f, "USE {}", db_name)?; Ok(()) diff --git a/src/keywords.rs b/src/keywords.rs index 30ec735f..2fa79855 100644 --- a/src/keywords.rs +++ b/src/keywords.rs @@ -250,6 +250,7 @@ define_keywords!( FROM, FULL, FUNCTION, + FUNCTIONS, FUSION, GET, GLOBAL, diff --git a/src/parser.rs b/src/parser.rs index 968b1a5d..a9ee5b0e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3854,6 +3854,8 @@ impl<'a> Parser<'a> { Ok(self.parse_show_columns(extended, full)?) } else if self.parse_keyword(Keyword::TABLES) { Ok(self.parse_show_tables(extended, full)?) + } else if self.parse_keyword(Keyword::FUNCTIONS) { + Ok(self.parse_show_functions()?) } else if extended || full { Err(ParserError::ParserError( "EXTENDED/FULL are not supported with this type of SHOW query".to_string(), @@ -3945,6 +3947,11 @@ impl<'a> Parser<'a> { }) } + pub fn parse_show_functions(&mut self) -> Result { + let filter = self.parse_show_statement_filter()?; + Ok(Statement::ShowFunctions { filter }) + } + pub fn parse_show_collation(&mut self) -> Result { let filter = self.parse_show_statement_filter()?; Ok(Statement::ShowCollation { filter }) diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index d2d2646c..7fb71ea9 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -5569,3 +5569,13 @@ fn parse_cursor() { _ => unreachable!(), } } + +#[test] +fn parse_show_functions() { + assert_eq!( + verified_stmt("SHOW FUNCTIONS LIKE 'pattern'"), + Statement::ShowFunctions { + filter: Some(ShowStatementFilter::Like("pattern".into())), + } + ); +}