snowflake: add qualify expression (#465)

Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
This commit is contained in:
Maciej Obuchowski 2022-04-29 20:11:11 +02:00 committed by GitHub
parent edad20cbb8
commit 525ba527bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 2 deletions

View file

@ -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,