Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4087,6 +4087,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 {
Expand Down Expand Up @@ -5710,6 +5721,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::ShowSchemas {
terse,
history,
Expand Down
1 change: 1 addition & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,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::ShowSchemas { .. } => Span::empty(),
Statement::ShowObjects { .. } => Span::empty(),
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ define_keywords!(
CASES,
CAST,
CATALOG,
CATALOGS,
CATALOG_SYNC,
CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER,
CATALOG_SYNC_NAMESPACE_MODE,
Expand Down
12 changes: 12 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15071,6 +15071,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) {
Expand All @@ -15094,6 +15096,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()?;
Expand Down
7 changes: 6 additions & 1 deletion tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14740,6 +14740,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",
Expand All @@ -14757,7 +14758,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);
Expand Down
60 changes: 60 additions & 0 deletions tests/sqlparser_databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down