mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-29 02:14:07 +00:00
add nulls first/last support to order by expression (#176)
Following `<sort specification list>` from the standard https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#_10_10_sort_specification_list
This commit is contained in:
parent
c918ff042d
commit
418b9631ce
5 changed files with 64 additions and 8 deletions
|
@ -746,14 +746,17 @@ fn parse_select_order_by() {
|
|||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("lname")),
|
||||
asc: Some(true),
|
||||
nulls_first: None,
|
||||
},
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("fname")),
|
||||
asc: Some(false),
|
||||
nulls_first: None,
|
||||
},
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("id")),
|
||||
asc: None,
|
||||
nulls_first: None,
|
||||
},
|
||||
],
|
||||
select.order_by
|
||||
|
@ -775,10 +778,35 @@ fn parse_select_order_by_limit() {
|
|||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("lname")),
|
||||
asc: Some(true),
|
||||
nulls_first: None,
|
||||
},
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("fname")),
|
||||
asc: Some(false),
|
||||
nulls_first: None,
|
||||
},
|
||||
],
|
||||
select.order_by
|
||||
);
|
||||
assert_eq!(Some(Expr::Value(number("2"))), select.limit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_select_order_by_nulls_order() {
|
||||
let sql = "SELECT id, fname, lname FROM customer WHERE id < 5 \
|
||||
ORDER BY lname ASC NULLS FIRST, fname DESC NULLS LAST LIMIT 2";
|
||||
let select = verified_query(sql);
|
||||
assert_eq!(
|
||||
vec![
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("lname")),
|
||||
asc: Some(true),
|
||||
nulls_first: Some(true),
|
||||
},
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("fname")),
|
||||
asc: Some(false),
|
||||
nulls_first: Some(false),
|
||||
},
|
||||
],
|
||||
select.order_by
|
||||
|
@ -1251,7 +1279,8 @@ fn parse_window_functions() {
|
|||
partition_by: vec![],
|
||||
order_by: vec![OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("dt")),
|
||||
asc: Some(false)
|
||||
asc: Some(false),
|
||||
nulls_first: None,
|
||||
}],
|
||||
window_frame: None,
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue