Skip to content

Commit de5df47

Browse files
committed
fix conflict
Signed-off-by: Smith Cruise <chendingchao1@126.com>
1 parent 6fa3614 commit de5df47

File tree

6 files changed

+104
-4
lines changed

6 files changed

+104
-4
lines changed

src/ast/mod.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,6 +4095,17 @@ pub enum Statement {
40954095
show_options: ShowStatementOptions,
40964096
},
40974097
/// ```sql
4098+
/// SHOW CATALOGS
4099+
/// ```
4100+
ShowCatalogs {
4101+
/// `true` when terse output format was requested.
4102+
terse: bool,
4103+
/// `true` when history information was requested.
4104+
history: bool,
4105+
/// Additional options for `SHOW CATALOGS`.
4106+
show_options: ShowStatementOptions,
4107+
},
4108+
/// ```sql
40984109
/// SHOW DATABASES
40994110
/// ```
41004111
ShowDatabases {
@@ -5728,14 +5739,24 @@ impl fmt::Display for Statement {
57285739
)?;
57295740
Ok(())
57305741
}
5731-
Statement::ShowProcessList { full } => {
5742+
Statement::ShowCatalogs {
5743+
terse,
5744+
history,
5745+
show_options,
5746+
} => {
57325747
write!(
57335748
f,
5734-
"SHOW {full}PROCESSLIST",
5735-
full = if *full { "FULL " } else { "" },
5749+
"SHOW {terse}CATALOGS{history}{show_options}",
5750+
terse = if *terse { "TERSE " } else { "" },
5751+
history = if *history { " HISTORY" } else { "" },
57365752
)?;
57375753
Ok(())
57385754
}
5755+
Statement::ShowProcessList { full } => {
5756+
write!(
5757+
f,
5758+
"SHOW {full}PROCESSLIST",
5759+
full = if *full { "FULL " } else { "" },
57395760
Statement::ShowSchemas {
57405761
terse,
57415762
history,

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ impl Spanned for Statement {
474474
Statement::AlterConnector { .. } => Span::empty(),
475475
Statement::DropPolicy { .. } => Span::empty(),
476476
Statement::DropConnector { .. } => Span::empty(),
477+
Statement::ShowCatalogs { .. } => Span::empty(),
477478
Statement::ShowDatabases { .. } => Span::empty(),
478479
Statement::ShowProcessList { .. } => Span::empty(),
479480
Statement::ShowSchemas { .. } => 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
@@ -15401,6 +15401,8 @@ impl<'a> Parser<'a> {
1540115401
session,
1540215402
global,
1540315403
})
15404+
} else if self.parse_keyword(Keyword::CATALOGS) {
15405+
self.parse_show_catalogs(terse)
1540415406
} else if self.parse_keyword(Keyword::DATABASES) {
1540515407
self.parse_show_databases(terse)
1540615408
} else if self.parse_keyword(Keyword::SCHEMAS) {
@@ -15424,6 +15426,16 @@ impl<'a> Parser<'a> {
1542415426
}))
1542515427
}
1542615428

15429+
fn parse_show_catalogs(&mut self, terse: bool) -> Result<Statement, ParserError> {
15430+
let history = self.parse_keyword(Keyword::HISTORY);
15431+
let show_options = self.parse_show_stmt_options()?;
15432+
Ok(Statement::ShowCatalogs {
15433+
terse,
15434+
history,
15435+
show_options,
15436+
})
15437+
}
15438+
1542715439
fn parse_show_databases(&mut self, terse: bool) -> Result<Statement, ParserError> {
1542815440
let history = self.parse_keyword(Keyword::HISTORY);
1542915441
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
@@ -14759,6 +14759,7 @@ fn parse_method_expr() {
1475914759
fn test_show_dbs_schemas_tables_views() {
1476014760
// These statements are parsed the same by all dialects
1476114761
let stmts = vec![
14762+
"SHOW CATALOGS",
1476214763
"SHOW DATABASES",
1476314764
"SHOW SCHEMAS",
1476414765
"SHOW TABLES",
@@ -14776,7 +14777,11 @@ fn test_show_dbs_schemas_tables_views() {
1477614777
// These statements are parsed the same by all dialects
1477714778
// except for how the parser interprets the location of
1477814779
// LIKE option (infix/suffix)
14779-
let stmts = vec!["SHOW DATABASES LIKE '%abc'", "SHOW SCHEMAS LIKE '%abc'"];
14780+
let stmts = vec![
14781+
"SHOW CATALOGS LIKE '%abc'",
14782+
"SHOW DATABASES LIKE '%abc'",
14783+
"SHOW SCHEMAS LIKE '%abc'",
14784+
];
1478014785
for stmt in stmts {
1478114786
all_dialects_where(|d| d.supports_show_like_before_in()).verified_stmt(stmt);
1478214787
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)