Skip to content

Commit 856234b

Browse files
committed
Add SHOW CATALOGS syntax and tests
1 parent 7c4eac3 commit 856234b

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed

src/ast/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,6 +4087,17 @@ pub enum Statement {
40874087
show_options: ShowStatementOptions,
40884088
},
40894089
/// ```sql
4090+
/// SHOW CATALOGS
4091+
/// ```
4092+
ShowCatalogs {
4093+
/// `true` when terse output format was requested.
4094+
terse: bool,
4095+
/// `true` when history information was requested.
4096+
history: bool,
4097+
/// Additional options for `SHOW CATALOGS`.
4098+
show_options: ShowStatementOptions,
4099+
},
4100+
/// ```sql
40904101
/// SHOW DATABASES
40914102
/// ```
40924103
ShowDatabases {
@@ -5710,6 +5721,19 @@ impl fmt::Display for Statement {
57105721
)?;
57115722
Ok(())
57125723
}
5724+
Statement::ShowCatalogs {
5725+
terse,
5726+
history,
5727+
show_options,
5728+
} => {
5729+
write!(
5730+
f,
5731+
"SHOW {terse}CATALOGS{history}{show_options}",
5732+
terse = if *terse { "TERSE " } else { "" },
5733+
history = if *history { " HISTORY" } else { "" },
5734+
)?;
5735+
Ok(())
5736+
}
57135737
Statement::ShowSchemas {
57145738
terse,
57155739
history,

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ impl Spanned for Statement {
473473
Statement::AlterConnector { .. } => Span::empty(),
474474
Statement::DropPolicy { .. } => Span::empty(),
475475
Statement::DropConnector { .. } => Span::empty(),
476+
Statement::ShowCatalogs { .. } => Span::empty(),
476477
Statement::ShowDatabases { .. } => Span::empty(),
477478
Statement::ShowSchemas { .. } => Span::empty(),
478479
Statement::ShowObjects { .. } => Span::empty(),

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ define_keywords!(
193193
CASES,
194194
CAST,
195195
CATALOG,
196+
CATALOGS,
196197
CATALOG_SYNC,
197198
CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER,
198199
CATALOG_SYNC_NAMESPACE_MODE,

src/parser/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15071,6 +15071,8 @@ impl<'a> Parser<'a> {
1507115071
session,
1507215072
global,
1507315073
})
15074+
} else if self.parse_keyword(Keyword::CATALOGS) {
15075+
self.parse_show_catalogs(terse)
1507415076
} else if self.parse_keyword(Keyword::DATABASES) {
1507515077
self.parse_show_databases(terse)
1507615078
} else if self.parse_keyword(Keyword::SCHEMAS) {
@@ -15094,6 +15096,16 @@ impl<'a> Parser<'a> {
1509415096
}))
1509515097
}
1509615098

15099+
fn parse_show_catalogs(&mut self, terse: bool) -> Result<Statement, ParserError> {
15100+
let history = self.parse_keyword(Keyword::HISTORY);
15101+
let show_options = self.parse_show_stmt_options()?;
15102+
Ok(Statement::ShowCatalogs {
15103+
terse,
15104+
history,
15105+
show_options,
15106+
})
15107+
}
15108+
1509715109
fn parse_show_databases(&mut self, terse: bool) -> Result<Statement, ParserError> {
1509815110
let history = self.parse_keyword(Keyword::HISTORY);
1509915111
let show_options = self.parse_show_stmt_options()?;

tests/sqlparser_common.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14740,6 +14740,7 @@ fn parse_method_expr() {
1474014740
fn test_show_dbs_schemas_tables_views() {
1474114741
// These statements are parsed the same by all dialects
1474214742
let stmts = vec![
14743+
"SHOW CATALOGS",
1474314744
"SHOW DATABASES",
1474414745
"SHOW SCHEMAS",
1474514746
"SHOW TABLES",
@@ -14757,7 +14758,11 @@ fn test_show_dbs_schemas_tables_views() {
1475714758
// These statements are parsed the same by all dialects
1475814759
// except for how the parser interprets the location of
1475914760
// LIKE option (infix/suffix)
14760-
let stmts = vec!["SHOW DATABASES LIKE '%abc'", "SHOW SCHEMAS LIKE '%abc'"];
14761+
let stmts = vec![
14762+
"SHOW CATALOGS LIKE '%abc'",
14763+
"SHOW DATABASES LIKE '%abc'",
14764+
"SHOW SCHEMAS LIKE '%abc'",
14765+
];
1476114766
for stmt in stmts {
1476214767
all_dialects_where(|d| d.supports_show_like_before_in()).verified_stmt(stmt);
1476314768
all_dialects_where(|d| !d.supports_show_like_before_in()).verified_stmt(stmt);

tests/sqlparser_databricks.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,66 @@ fn parse_use() {
299299
}
300300
}
301301

302+
#[test]
303+
fn parse_show_catalogs() {
304+
databricks().verified_stmt("SHOW CATALOGS");
305+
databricks().verified_stmt("SHOW TERSE CATALOGS");
306+
databricks().verified_stmt("SHOW CATALOGS HISTORY");
307+
databricks().verified_stmt("SHOW CATALOGS LIKE 'pay*'");
308+
databricks().verified_stmt("SHOW CATALOGS 'pay*'");
309+
databricks().verified_stmt("SHOW CATALOGS STARTS WITH 'pay'");
310+
databricks().verified_stmt("SHOW CATALOGS LIMIT 10");
311+
databricks().verified_stmt("SHOW CATALOGS HISTORY STARTS WITH 'pay'");
312+
313+
match databricks().verified_stmt("SHOW CATALOGS LIKE 'pay*'") {
314+
Statement::ShowCatalogs {
315+
terse,
316+
history,
317+
show_options,
318+
} => {
319+
assert!(!terse);
320+
assert!(!history);
321+
assert_eq!(show_options.show_in, None);
322+
assert_eq!(show_options.starts_with, None);
323+
assert_eq!(show_options.limit, None);
324+
assert_eq!(show_options.limit_from, None);
325+
assert_eq!(
326+
show_options.filter_position,
327+
Some(ShowStatementFilterPosition::Suffix(
328+
ShowStatementFilter::Like("pay*".to_string())
329+
))
330+
);
331+
}
332+
_ => unreachable!(),
333+
}
334+
}
335+
336+
#[test]
337+
fn parse_show_catalogs_with_show_options() {
338+
databricks().verified_stmt("SHOW TERSE CATALOGS HISTORY IN ACCOUNT");
339+
340+
match databricks().verified_stmt("SHOW TERSE CATALOGS HISTORY IN ACCOUNT") {
341+
Statement::ShowCatalogs {
342+
terse,
343+
history,
344+
show_options,
345+
} => {
346+
assert!(terse);
347+
assert!(history);
348+
assert_eq!(show_options.filter_position, None);
349+
assert!(matches!(
350+
show_options.show_in,
351+
Some(ShowStatementIn {
352+
parent_type: Some(ShowStatementInParentType::Account),
353+
parent_name: None,
354+
..
355+
})
356+
));
357+
}
358+
_ => unreachable!(),
359+
}
360+
}
361+
302362
#[test]
303363
fn parse_databricks_struct_function() {
304364
assert_eq!(

0 commit comments

Comments
 (0)