mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 18:57:21 +00:00
Parse an optional column list after a CTE
This commit is contained in:
parent
f859c9b80e
commit
cccf7f0d8e
3 changed files with 40 additions and 11 deletions
|
@ -1027,9 +1027,14 @@ fn parse_ctes() {
|
|||
fn assert_ctes_in_select(expected: &[&str], sel: &SQLQuery) {
|
||||
let mut i = 0;
|
||||
for exp in expected {
|
||||
let Cte { query, alias } = &sel.ctes[i];
|
||||
let Cte {
|
||||
query,
|
||||
alias,
|
||||
renamed_columns,
|
||||
} = &sel.ctes[i];
|
||||
assert_eq!(*exp, query.to_string());
|
||||
assert_eq!(if i == 0 { "a" } else { "b" }, alias);
|
||||
assert!(renamed_columns.is_empty());
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
@ -1066,6 +1071,16 @@ fn parse_ctes() {
|
|||
assert_ctes_in_select(&cte_sqls, &only(&select.ctes).query);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_cte_renamed_columns() {
|
||||
let sql = "WITH cte (col1, col2) AS (SELECT foo, bar FROM baz) SELECT * FROM cte";
|
||||
let query = all_dialects().verified_query(sql);
|
||||
assert_eq!(
|
||||
vec!["col1", "col2"],
|
||||
query.ctes.first().unwrap().renamed_columns
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_derived_tables() {
|
||||
let sql = "SELECT a.x, b.y FROM (SELECT x FROM foo) AS a CROSS JOIN (SELECT y FROM bar) AS b";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue