@@ -875,6 +875,7 @@ fn parse_select_count_wildcard() {
875875 & Expr :: Function ( Function {
876876 name: ObjectName ( vec![ Ident :: new( "COUNT" ) ] ) ,
877877 args: vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Wildcard ) ] ,
878+ null_treatment: None ,
878879 filter: None ,
879880 over: None ,
880881 distinct: false ,
@@ -896,6 +897,7 @@ fn parse_select_count_distinct() {
896897 op: UnaryOperator :: Plus ,
897898 expr: Box :: new( Expr :: Identifier ( Ident :: new( "x" ) ) ) ,
898899 } ) ) ] ,
900+ null_treatment: None ,
899901 filter: None ,
900902 over: None ,
901903 distinct: true ,
@@ -1864,6 +1866,7 @@ fn parse_select_having() {
18641866 left: Box :: new( Expr :: Function ( Function {
18651867 name: ObjectName ( vec![ Ident :: new( "COUNT" ) ] ) ,
18661868 args: vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Wildcard ) ] ,
1869+ null_treatment: None ,
18671870 filter: None ,
18681871 over: None ,
18691872 distinct: false ,
@@ -1890,6 +1893,7 @@ fn parse_select_qualify() {
18901893 left: Box :: new( Expr :: Function ( Function {
18911894 name: ObjectName ( vec![ Ident :: new( "ROW_NUMBER" ) ] ) ,
18921895 args: vec![ ] ,
1896+ null_treatment: None ,
18931897 filter: None ,
18941898 over: Some ( WindowType :: WindowSpec ( WindowSpec {
18951899 partition_by: vec![ Expr :: Identifier ( Ident :: new( "p" ) ) ] ,
@@ -2287,6 +2291,45 @@ fn parse_agg_with_order_by() {
22872291 }
22882292}
22892293
2294+ #[ test]
2295+ fn parse_window_rank_function ( ) {
2296+ let supported_dialects = TestedDialects {
2297+ dialects : vec ! [
2298+ Box :: new( GenericDialect { } ) ,
2299+ Box :: new( PostgreSqlDialect { } ) ,
2300+ Box :: new( MsSqlDialect { } ) ,
2301+ Box :: new( AnsiDialect { } ) ,
2302+ Box :: new( HiveDialect { } ) ,
2303+ Box :: new( SnowflakeDialect { } ) ,
2304+ ] ,
2305+ options : None ,
2306+ } ;
2307+
2308+ for sql in [
2309+ "SELECT column1, column2, FIRST_VALUE(column2) OVER (PARTITION BY column1 ORDER BY column2 NULLS LAST) AS column2_first FROM t1" ,
2310+ "SELECT column1, column2, FIRST_VALUE(column2) OVER (ORDER BY column2 NULLS LAST) AS column2_first FROM t1" ,
2311+ "SELECT col_1, col_2, LAG(col_2) OVER (ORDER BY col_1) FROM t1" ,
2312+ "SELECT LAG(col_2, 1, 0) OVER (ORDER BY col_1) FROM t1" ,
2313+ "SELECT LAG(col_2, 1, 0) OVER (PARTITION BY col_3 ORDER BY col_1)" ,
2314+ ] {
2315+ supported_dialects. verified_stmt ( sql) ;
2316+ }
2317+
2318+ let supported_dialects_nulls = TestedDialects {
2319+ dialects : vec ! [ Box :: new( MsSqlDialect { } ) , Box :: new( SnowflakeDialect { } ) ] ,
2320+ options : None ,
2321+ } ;
2322+
2323+ for sql in [
2324+ "SELECT column1, column2, FIRST_VALUE(column2) IGNORE NULLS OVER (PARTITION BY column1 ORDER BY column2 NULLS LAST) AS column2_first FROM t1" ,
2325+ "SELECT column1, column2, FIRST_VALUE(column2) RESPECT NULLS OVER (PARTITION BY column1 ORDER BY column2 NULLS LAST) AS column2_first FROM t1" ,
2326+ "SELECT LAG(col_2, 1, 0) IGNORE NULLS OVER (ORDER BY col_1) FROM t1" ,
2327+ "SELECT LAG(col_2, 1, 0) RESPECT NULLS OVER (ORDER BY col_1) FROM t1" ,
2328+ ] {
2329+ supported_dialects_nulls. verified_stmt ( sql) ;
2330+ }
2331+ }
2332+
22902333#[ test]
22912334fn parse_create_table ( ) {
22922335 let sql = "CREATE TABLE uk_cities (\
@@ -3346,6 +3389,7 @@ fn parse_scalar_function_in_projection() {
33463389 args: vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr (
33473390 Expr :: Identifier ( Ident :: new( "id" ) )
33483391 ) ) ] ,
3392+ null_treatment: None ,
33493393 filter: None ,
33503394 over: None ,
33513395 distinct: false ,
@@ -3466,6 +3510,7 @@ fn parse_named_argument_function() {
34663510 ) ) ) ,
34673511 } ,
34683512 ] ,
3513+ null_treatment: None ,
34693514 filter: None ,
34703515 over: None ,
34713516 distinct: false ,
@@ -3498,6 +3543,7 @@ fn parse_window_functions() {
34983543 & Expr :: Function ( Function {
34993544 name: ObjectName ( vec![ Ident :: new( "row_number" ) ] ) ,
35003545 args: vec![ ] ,
3546+ null_treatment: None ,
35013547 filter: None ,
35023548 over: Some ( WindowType :: WindowSpec ( WindowSpec {
35033549 partition_by: vec![ ] ,
@@ -3542,6 +3588,7 @@ fn test_parse_named_window() {
35423588 quote_style: None ,
35433589 } ) ,
35443590 ) ) ] ,
3591+ null_treatment: None ,
35453592 filter: None ,
35463593 over: Some ( WindowType :: NamedWindow ( Ident {
35473594 value: "window1" . to_string( ) ,
@@ -3568,6 +3615,7 @@ fn test_parse_named_window() {
35683615 quote_style: None ,
35693616 } ) ,
35703617 ) ) ] ,
3618+ null_treatment: None ,
35713619 filter: None ,
35723620 over: Some ( WindowType :: NamedWindow ( Ident {
35733621 value: "window2" . to_string( ) ,
@@ -4038,6 +4086,7 @@ fn parse_at_timezone() {
40384086 quote_style: None ,
40394087 } ] ) ,
40404088 args: vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( zero. clone( ) ) ) ] ,
4089+ null_treatment: None ,
40414090 filter: None ,
40424091 over: None ,
40434092 distinct: false ,
@@ -4066,6 +4115,7 @@ fn parse_at_timezone() {
40664115 quote_style: None ,
40674116 } , ] , ) ,
40684117 args: vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( zero) ) ] ,
4118+ null_treatment: None ,
40694119 filter: None ,
40704120 over: None ,
40714121 distinct: false ,
@@ -4078,6 +4128,7 @@ fn parse_at_timezone() {
40784128 Value :: SingleQuotedString ( "%Y-%m-%dT%H" . to_string( ) ) ,
40794129 ) , ) , ) ,
40804130 ] ,
4131+ null_treatment: None ,
40814132 filter: None ,
40824133 over: None ,
40834134 distinct: false ,
@@ -4237,6 +4288,7 @@ fn parse_table_function() {
42374288 args : vec ! [ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( Expr :: Value (
42384289 Value :: SingleQuotedString ( "1" . to_owned( ) ) ,
42394290 ) ) ) ] ,
4291+ null_treatment : None ,
42404292 filter : None ,
42414293 over : None ,
42424294 distinct : false ,
@@ -4389,6 +4441,7 @@ fn parse_unnest_in_from_clause() {
43894441 FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( Expr :: Value ( number( "2" ) ) ) ) ,
43904442 FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( Expr :: Value ( number( "3" ) ) ) ) ,
43914443 ] ,
4444+ null_treatment: None ,
43924445 filter: None ,
43934446 over: None ,
43944447 distinct: false ,
@@ -4419,6 +4472,7 @@ fn parse_unnest_in_from_clause() {
44194472 FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( Expr :: Value ( number( "2" ) ) ) ) ,
44204473 FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( Expr :: Value ( number( "3" ) ) ) ) ,
44214474 ] ,
4475+ null_treatment: None ,
44224476 filter: None ,
44234477 over: None ,
44244478 distinct: false ,
@@ -4431,6 +4485,7 @@ fn parse_unnest_in_from_clause() {
44314485 FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( Expr :: Value ( number( "5" ) ) ) ) ,
44324486 FunctionArg :: Unnamed ( FunctionArgExpr :: Expr ( Expr :: Value ( number( "6" ) ) ) ) ,
44334487 ] ,
4488+ null_treatment: None ,
44344489 filter: None ,
44354490 over: None ,
44364491 distinct: false ,
@@ -6904,6 +6959,7 @@ fn parse_time_functions() {
69046959 let select_localtime_func_call_ast = Function {
69056960 name : ObjectName ( vec ! [ Ident :: new( func_name) ] ) ,
69066961 args : vec ! [ ] ,
6962+ null_treatment : None ,
69076963 filter : None ,
69086964 over : None ,
69096965 distinct : false ,
@@ -7391,6 +7447,7 @@ fn parse_pivot_table() {
73917447 args: ( vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr (
73927448 Expr :: CompoundIdentifier ( vec![ Ident :: new( "a" ) , Ident :: new( "amount" ) , ] )
73937449 ) ) ] ) ,
7450+ null_treatment: None ,
73947451 filter: None ,
73957452 over: None ,
73967453 distinct: false ,
@@ -7541,6 +7598,7 @@ fn parse_pivot_unpivot_table() {
75417598 args: ( vec![ FunctionArg :: Unnamed ( FunctionArgExpr :: Expr (
75427599 Expr :: Identifier ( Ident :: new( "population" ) )
75437600 ) ) ] ) ,
7601+ null_treatment: None ,
75447602 filter: None ,
75457603 over: None ,
75467604 distinct: false ,
0 commit comments