File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -3518,7 +3518,7 @@ impl fmt::Display for ListAggOnOverflow {
3518
3518
pub struct ArrayAgg {
3519
3519
pub distinct : bool ,
3520
3520
pub expr : Box < Expr > ,
3521
- pub order_by : Option < Box < OrderByExpr > > ,
3521
+ pub order_by : Option < Vec < OrderByExpr > > ,
3522
3522
pub limit : Option < Box < Expr > > ,
3523
3523
pub within_group : bool , // order by is used inside a within group or not
3524
3524
}
@@ -3533,7 +3533,7 @@ impl fmt::Display for ArrayAgg {
3533
3533
) ?;
3534
3534
if !self . within_group {
3535
3535
if let Some ( order_by) = & self . order_by {
3536
- write ! ( f, " ORDER BY {order_by}" ) ?;
3536
+ write ! ( f, " ORDER BY {}" , display_comma_separated ( order_by ) ) ?;
3537
3537
}
3538
3538
if let Some ( limit) = & self . limit {
3539
3539
write ! ( f, " LIMIT {limit}" ) ?;
@@ -3542,7 +3542,11 @@ impl fmt::Display for ArrayAgg {
3542
3542
write ! ( f, ")" ) ?;
3543
3543
if self . within_group {
3544
3544
if let Some ( order_by) = & self . order_by {
3545
- write ! ( f, " WITHIN GROUP (ORDER BY {order_by})" ) ?;
3545
+ write ! (
3546
+ f,
3547
+ " WITHIN GROUP (ORDER BY {})" ,
3548
+ display_comma_separated( order_by)
3549
+ ) ?;
3546
3550
}
3547
3551
}
3548
3552
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -1369,8 +1369,7 @@ impl<'a> Parser<'a> {
1369
1369
// ANSI SQL and BigQuery define ORDER BY inside function.
1370
1370
if !self . dialect . supports_within_after_array_aggregation ( ) {
1371
1371
let order_by = if self . parse_keywords ( & [ Keyword :: ORDER , Keyword :: BY ] ) {
1372
- let order_by_expr = self . parse_order_by_expr ( ) ?;
1373
- Some ( Box :: new ( order_by_expr) )
1372
+ Some ( self . parse_comma_separated ( Parser :: parse_order_by_expr) ?)
1374
1373
} else {
1375
1374
None
1376
1375
} ;
@@ -1393,10 +1392,13 @@ impl<'a> Parser<'a> {
1393
1392
self . expect_token ( & Token :: RParen ) ?;
1394
1393
let within_group = if self . parse_keywords ( & [ Keyword :: WITHIN , Keyword :: GROUP ] ) {
1395
1394
self . expect_token ( & Token :: LParen ) ?;
1396
- self . expect_keywords ( & [ Keyword :: ORDER , Keyword :: BY ] ) ?;
1397
- let order_by_expr = self . parse_order_by_expr ( ) ?;
1395
+ let order_by = if self . parse_keywords ( & [ Keyword :: ORDER , Keyword :: BY ] ) {
1396
+ Some ( self . parse_comma_separated ( Parser :: parse_order_by_expr) ?)
1397
+ } else {
1398
+ None
1399
+ } ;
1398
1400
self . expect_token ( & Token :: RParen ) ?;
1399
- Some ( Box :: new ( order_by_expr ) )
1401
+ order_by
1400
1402
} else {
1401
1403
None
1402
1404
} ;
Original file line number Diff line number Diff line change @@ -2065,6 +2065,8 @@ fn parse_array_agg_func() {
2065
2065
"SELECT ARRAY_AGG(x ORDER BY x) AS a FROM T" ,
2066
2066
"SELECT ARRAY_AGG(x ORDER BY x LIMIT 2) FROM tbl" ,
2067
2067
"SELECT ARRAY_AGG(DISTINCT x ORDER BY x LIMIT 2) FROM tbl" ,
2068
+ "SELECT ARRAY_AGG(x ORDER BY x, y) AS a FROM T" ,
2069
+ "SELECT ARRAY_AGG(x ORDER BY x ASC, y DESC) AS a FROM T" ,
2068
2070
] {
2069
2071
supported_dialects. verified_stmt ( sql) ;
2070
2072
}
You can’t perform that action at this time.
0 commit comments