mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 03:07:20 +00:00
snowflake: add qualify expression (#465)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
This commit is contained in:
parent
edad20cbb8
commit
525ba527bb
7 changed files with 60 additions and 2 deletions
|
@ -1322,6 +1322,45 @@ fn parse_select_having() {
|
|||
assert!(select.having.is_some());
|
||||
}
|
||||
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
#[test]
|
||||
fn parse_select_qualify() {
|
||||
let sql = "SELECT i, p, o FROM qt QUALIFY ROW_NUMBER() OVER (PARTITION BY p ORDER BY o) = 1";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Some(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Function(Function {
|
||||
name: ObjectName(vec![Ident::new("ROW_NUMBER")]),
|
||||
args: vec![],
|
||||
over: Some(WindowSpec {
|
||||
partition_by: vec![Expr::Identifier(Ident::new("p"))],
|
||||
order_by: vec![OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("o")),
|
||||
asc: None,
|
||||
nulls_first: None
|
||||
}],
|
||||
window_frame: None
|
||||
}),
|
||||
distinct: false
|
||||
})),
|
||||
op: BinaryOperator::Eq,
|
||||
right: Box::new(Expr::Value(number("1")))
|
||||
}),
|
||||
select.qualify
|
||||
);
|
||||
|
||||
let sql = "SELECT i, p, o, ROW_NUMBER() OVER (PARTITION BY p ORDER BY o) AS row_num FROM qt QUALIFY row_num = 1";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Some(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("row_num"))),
|
||||
op: BinaryOperator::Eq,
|
||||
right: Box::new(Expr::Value(number("1")))
|
||||
}),
|
||||
select.qualify
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_limit_accepts_all() {
|
||||
one_statement_parses_to(
|
||||
|
@ -4336,7 +4375,8 @@ fn parse_merge() {
|
|||
cluster_by: vec![],
|
||||
distribute_by: vec![],
|
||||
sort_by: vec![],
|
||||
having: None
|
||||
having: None,
|
||||
qualify: None
|
||||
})),
|
||||
order_by: vec![],
|
||||
limit: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue