mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-29 10:24:06 +00:00
feat: Add WITH OFFSET Alias (#528)
* feat: Add WITH OFFSET Alias * update: fix with_offset_alias type
This commit is contained in:
parent
17c238bda7
commit
68768530cd
3 changed files with 53 additions and 2 deletions
|
@ -2837,11 +2837,22 @@ fn parse_table_function() {
|
|||
|
||||
#[test]
|
||||
fn parse_unnest() {
|
||||
fn chk(alias: bool, with_offset: bool, dialects: &TestedDialects, want: Vec<TableWithJoins>) {
|
||||
fn chk(
|
||||
alias: bool,
|
||||
with_offset: bool,
|
||||
with_offset_alias: bool,
|
||||
dialects: &TestedDialects,
|
||||
want: Vec<TableWithJoins>,
|
||||
) {
|
||||
let sql = &format!(
|
||||
"SELECT * FROM UNNEST(expr){}{}",
|
||||
"SELECT * FROM UNNEST(expr){}{}{}",
|
||||
if alias { " AS numbers" } else { "" },
|
||||
if with_offset { " WITH OFFSET" } else { "" },
|
||||
if with_offset_alias {
|
||||
" AS with_offset_alias"
|
||||
} else {
|
||||
""
|
||||
},
|
||||
);
|
||||
let select = dialects.verified_only_select(sql);
|
||||
assert_eq!(select.from, want);
|
||||
|
@ -2853,6 +2864,7 @@ fn parse_unnest() {
|
|||
chk(
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
&dialects,
|
||||
vec![TableWithJoins {
|
||||
relation: TableFactor::UNNEST {
|
||||
|
@ -2862,12 +2874,14 @@ fn parse_unnest() {
|
|||
}),
|
||||
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
|
||||
with_offset: true,
|
||||
with_offset_alias: None,
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
);
|
||||
// 2. neither Alias nor WITH OFFSET clause.
|
||||
chk(
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
&dialects,
|
||||
|
@ -2876,6 +2890,7 @@ fn parse_unnest() {
|
|||
alias: None,
|
||||
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
|
||||
with_offset: false,
|
||||
with_offset_alias: None,
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
|
@ -2884,12 +2899,14 @@ fn parse_unnest() {
|
|||
chk(
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
&dialects,
|
||||
vec![TableWithJoins {
|
||||
relation: TableFactor::UNNEST {
|
||||
alias: None,
|
||||
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
|
||||
with_offset: true,
|
||||
with_offset_alias: None,
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
|
@ -2898,6 +2915,7 @@ fn parse_unnest() {
|
|||
chk(
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
&dialects,
|
||||
vec![TableWithJoins {
|
||||
relation: TableFactor::UNNEST {
|
||||
|
@ -2907,6 +2925,26 @@ fn parse_unnest() {
|
|||
}),
|
||||
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
|
||||
with_offset: false,
|
||||
with_offset_alias: None,
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
);
|
||||
// 5. WITH OFFSET and WITH OFFSET Alias
|
||||
chk(
|
||||
true,
|
||||
false,
|
||||
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: false,
|
||||
with_offset_alias: Some(Ident::new("with_offset_alias")),
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue