mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-02 20:27:21 +00:00
Support UNNEST
as a table factor (#493)
* support unnest * add test * fix ast * Update condition for BigQueryDialect or GenericDialect I updated condition. This changes conditionalize parsing for only BigQueryDialect or GenericDialect. * Add some tests * fix test
This commit is contained in:
parent
d19c6c323c
commit
aa46e930c5
3 changed files with 130 additions and 1 deletions
|
@ -2786,6 +2786,84 @@ fn parse_table_function() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_unnest() {
|
||||
fn chk(alias: bool, with_offset: bool, dialects: &TestedDialects, want: Vec<TableWithJoins>) {
|
||||
let sql = &format!(
|
||||
"SELECT * FROM UNNEST(expr){}{}",
|
||||
if alias { " AS numbers" } else { "" },
|
||||
if with_offset { " WITH OFFSET" } else { "" },
|
||||
);
|
||||
let select = dialects.verified_only_select(sql);
|
||||
assert_eq!(select.from, want);
|
||||
}
|
||||
let dialects = TestedDialects {
|
||||
dialects: vec![Box::new(BigQueryDialect {}), Box::new(GenericDialect {})],
|
||||
};
|
||||
// 1. both Alias and WITH OFFSET clauses.
|
||||
chk(
|
||||
true,
|
||||
true,
|
||||
&dialects,
|
||||
vec![TableWithJoins {
|
||||
relation: TableFactor::UNNEST {
|
||||
alias: Some(TableAlias {
|
||||
name: Ident::new("numbers"),
|
||||
columns: vec![],
|
||||
}),
|
||||
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
|
||||
with_offset: true,
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
);
|
||||
// 2. neither Alias nor WITH OFFSET clause.
|
||||
chk(
|
||||
false,
|
||||
false,
|
||||
&dialects,
|
||||
vec![TableWithJoins {
|
||||
relation: TableFactor::UNNEST {
|
||||
alias: None,
|
||||
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
|
||||
with_offset: false,
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
);
|
||||
// 3. Alias but no WITH OFFSET clause.
|
||||
chk(
|
||||
false,
|
||||
true,
|
||||
&dialects,
|
||||
vec![TableWithJoins {
|
||||
relation: TableFactor::UNNEST {
|
||||
alias: None,
|
||||
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
|
||||
with_offset: true,
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
);
|
||||
// 4. WITH OFFSET but no Alias.
|
||||
chk(
|
||||
true,
|
||||
false,
|
||||
&dialects,
|
||||
vec![TableWithJoins {
|
||||
relation: TableFactor::UNNEST {
|
||||
alias: Some(TableAlias {
|
||||
name: Ident::new("numbers"),
|
||||
columns: vec![],
|
||||
}),
|
||||
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
|
||||
with_offset: false,
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_delimited_identifiers() {
|
||||
// check that quoted identifiers in any position remain quoted after serialization
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue