You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/04/15 10:23:14 UTC

(datafusion-sqlparser-rs) 01/01: Add SHOW CATALOGS syntax and tests (#2284)

This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch gh-readonly-queue/main/pr-2284-93bc80c946ff32aa065ddaafbbef62ac69c43909
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit 073df280024abfba81769242298450324d958228
Author: Smith Cruise <ch...@126.com>
AuthorDate: Wed Apr 15 18:22:49 2026 +0800

    Add SHOW CATALOGS syntax and tests (#2284)
    
    Signed-off-by: Smith Cruise <ch...@126.com>
---
 src/ast/mod.rs                | 24 +++++++++++++++++
 src/ast/spans.rs              |  1 +
 src/keywords.rs               |  1 +
 src/parser/mod.rs             | 12 +++++++++
 tests/sqlparser_common.rs     |  7 ++++-
 tests/sqlparser_databricks.rs | 60 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 58a454df..63b3db64 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -4109,6 +4109,17 @@ pub enum Statement {
         show_options: ShowStatementOptions,
     },
     /// ```sql
+    /// SHOW CATALOGS
+    /// ```
+    ShowCatalogs {
+        /// `true` when terse output format was requested.
+        terse: bool,
+        /// `true` when history information was requested.
+        history: bool,
+        /// Additional options for `SHOW CATALOGS`.
+        show_options: ShowStatementOptions,
+    },
+    /// ```sql
     /// SHOW DATABASES
     /// ```
     ShowDatabases {
@@ -5744,6 +5755,19 @@ impl fmt::Display for Statement {
                 )?;
                 Ok(())
             }
+            Statement::ShowCatalogs {
+                terse,
+                history,
+                show_options,
+            } => {
+                write!(
+                    f,
+                    "SHOW {terse}CATALOGS{history}{show_options}",
+                    terse = if *terse { "TERSE " } else { "" },
+                    history = if *history { " HISTORY" } else { "" },
+                )?;
+                Ok(())
+            }
             Statement::ShowProcessList { full } => {
                 write!(
                     f,
diff --git a/src/ast/spans.rs b/src/ast/spans.rs
index 9a32dc5a..e7a8f94f 100644
--- a/src/ast/spans.rs
+++ b/src/ast/spans.rs
@@ -478,6 +478,7 @@ impl Spanned for Statement {
             Statement::AlterConnector { .. } => Span::empty(),
             Statement::DropPolicy { .. } => Span::empty(),
             Statement::DropConnector { .. } => Span::empty(),
+            Statement::ShowCatalogs { .. } => Span::empty(),
             Statement::ShowDatabases { .. } => Span::empty(),
             Statement::ShowProcessList { .. } => Span::empty(),
             Statement::ShowSchemas { .. } => Span::empty(),
diff --git a/src/keywords.rs b/src/keywords.rs
index 4ed30d24..808e5f03 100644
--- a/src/keywords.rs
+++ b/src/keywords.rs
@@ -193,6 +193,7 @@ define_keywords!(
     CASES,
     CAST,
     CATALOG,
+    CATALOGS,
     CATALOG_SYNC,
     CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER,
     CATALOG_SYNC_NAMESPACE_MODE,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 2b2aef89..a5526723 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -15465,6 +15465,8 @@ impl<'a> Parser<'a> {
                 session,
                 global,
             })
+        } else if self.parse_keyword(Keyword::CATALOGS) {
+            self.parse_show_catalogs(terse)
         } else if self.parse_keyword(Keyword::DATABASES) {
             self.parse_show_databases(terse)
         } else if self.parse_keyword(Keyword::SCHEMAS) {
@@ -15488,6 +15490,16 @@ impl<'a> Parser<'a> {
         }))
     }
 
+    fn parse_show_catalogs(&mut self, terse: bool) -> Result<Statement, ParserError> {
+        let history = self.parse_keyword(Keyword::HISTORY);
+        let show_options = self.parse_show_stmt_options()?;
+        Ok(Statement::ShowCatalogs {
+            terse,
+            history,
+            show_options,
+        })
+    }
+
     fn parse_show_databases(&mut self, terse: bool) -> Result<Statement, ParserError> {
         let history = self.parse_keyword(Keyword::HISTORY);
         let show_options = self.parse_show_stmt_options()?;
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index d516afe2..c76899f0 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -14772,6 +14772,7 @@ fn parse_method_expr() {
 fn test_show_dbs_schemas_tables_views() {
     // These statements are parsed the same by all dialects
     let stmts = vec![
+        "SHOW CATALOGS",
         "SHOW DATABASES",
         "SHOW SCHEMAS",
         "SHOW TABLES",
@@ -14789,7 +14790,11 @@ fn test_show_dbs_schemas_tables_views() {
     // These statements are parsed the same by all dialects
     // except for how the parser interprets the location of
     // LIKE option (infix/suffix)
-    let stmts = vec!["SHOW DATABASES LIKE '%abc'", "SHOW SCHEMAS LIKE '%abc'"];
+    let stmts = vec![
+        "SHOW CATALOGS LIKE '%abc'",
+        "SHOW DATABASES LIKE '%abc'",
+        "SHOW SCHEMAS LIKE '%abc'",
+    ];
     for stmt in stmts {
         all_dialects_where(|d| d.supports_show_like_before_in()).verified_stmt(stmt);
         all_dialects_where(|d| !d.supports_show_like_before_in()).verified_stmt(stmt);
diff --git a/tests/sqlparser_databricks.rs b/tests/sqlparser_databricks.rs
index dd7d2881..405dffaf 100644
--- a/tests/sqlparser_databricks.rs
+++ b/tests/sqlparser_databricks.rs
@@ -299,6 +299,66 @@ fn parse_use() {
     }
 }
 
+#[test]
+fn parse_show_catalogs() {
+    databricks().verified_stmt("SHOW CATALOGS");
+    databricks().verified_stmt("SHOW TERSE CATALOGS");
+    databricks().verified_stmt("SHOW CATALOGS HISTORY");
+    databricks().verified_stmt("SHOW CATALOGS LIKE 'pay*'");
+    databricks().verified_stmt("SHOW CATALOGS 'pay*'");
+    databricks().verified_stmt("SHOW CATALOGS STARTS WITH 'pay'");
+    databricks().verified_stmt("SHOW CATALOGS LIMIT 10");
+    databricks().verified_stmt("SHOW CATALOGS HISTORY STARTS WITH 'pay'");
+
+    match databricks().verified_stmt("SHOW CATALOGS LIKE 'pay*'") {
+        Statement::ShowCatalogs {
+            terse,
+            history,
+            show_options,
+        } => {
+            assert!(!terse);
+            assert!(!history);
+            assert_eq!(show_options.show_in, None);
+            assert_eq!(show_options.starts_with, None);
+            assert_eq!(show_options.limit, None);
+            assert_eq!(show_options.limit_from, None);
+            assert_eq!(
+                show_options.filter_position,
+                Some(ShowStatementFilterPosition::Suffix(
+                    ShowStatementFilter::Like("pay*".to_string())
+                ))
+            );
+        }
+        _ => unreachable!(),
+    }
+}
+
+#[test]
+fn parse_show_catalogs_with_show_options() {
+    databricks().verified_stmt("SHOW TERSE CATALOGS HISTORY IN ACCOUNT");
+
+    match databricks().verified_stmt("SHOW TERSE CATALOGS HISTORY IN ACCOUNT") {
+        Statement::ShowCatalogs {
+            terse,
+            history,
+            show_options,
+        } => {
+            assert!(terse);
+            assert!(history);
+            assert_eq!(show_options.filter_position, None);
+            assert!(matches!(
+                show_options.show_in,
+                Some(ShowStatementIn {
+                    parent_type: Some(ShowStatementInParentType::Account),
+                    parent_name: None,
+                    ..
+                })
+            ));
+        }
+        _ => unreachable!(),
+    }
+}
+
 #[test]
 fn parse_databricks_struct_function() {
     assert_eq!(


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org