Skip to content

Commit

Permalink
test with a non-aggregate window function name
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Oct 20, 2023
1 parent 9b7f67d commit dd51436
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions tests/sqlparser_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,27 +292,35 @@ fn parse_create_table_with_strict() {

#[test]
fn parse_window_function_with_filter() {
let sql = "SELECT max(x) FILTER (WHERE y) OVER () FROM t";
let select = sqlite().verified_only_select(sql);
assert_eq!(select.to_string(), sql);
assert_eq!(
select.projection,
vec![SelectItem::UnnamedExpr(Expr::Function(Function {
name: ObjectName(vec![Ident::new("max")]),
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(
Expr::Identifier(Ident::new("x"))
))],
over: Some(WindowType::WindowSpec(WindowSpec {
partition_by: vec![],
order_by: vec![],
window_frame: None,
})),
filter: Some(Box::new(Expr::Identifier(Ident::new("y")))),
distinct: false,
special: false,
order_by: vec![]
}))]
);
for func_name in [
"row_number",
"rank",
"max",
"count",
"user_defined_function",
] {
let sql = format!("SELECT {}(x) FILTER (WHERE y) OVER () FROM t", func_name);
let select = sqlite().verified_only_select(&sql);
assert_eq!(select.to_string(), sql);
assert_eq!(
select.projection,
vec![SelectItem::UnnamedExpr(Expr::Function(Function {
name: ObjectName(vec![Ident::new(func_name)]),
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(
Expr::Identifier(Ident::new("x"))
))],
over: Some(WindowType::WindowSpec(WindowSpec {
partition_by: vec![],
order_by: vec![],
window_frame: None,
})),
filter: Some(Box::new(Expr::Identifier(Ident::new("y")))),
distinct: false,
special: false,
order_by: vec![]
}))]
);
}
}

#[test]
Expand Down

0 comments on commit dd51436

Please sign in to comment.