Skip to content

Commit 5a49c3f

Browse files
fix(optimizer)!: support ORDER / LIMIT expressions for BigQuery ARRAY_AGG / STRING_AGG functions (#6463)
1 parent 7d485c7 commit 5a49c3f

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

sqlglot/typing/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@
212212
exp.ArraySlice,
213213
exp.Filter,
214214
exp.LastValue,
215+
exp.Limit,
216+
exp.Order,
215217
exp.SortArray,
216218
exp.Window,
217219
}

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,46 @@ STRING;
15881588
STRING_AGG(tbl.bin_col);
15891589
BINARY;
15901590

1591+
# dialect: bigquery
1592+
STRING_AGG(DISTINCT tbl.str_col);
1593+
STRING;
1594+
1595+
# dialect: bigquery
1596+
STRING_AGG(tbl.str_col ORDER BY tbl.str_col);
1597+
STRING;
1598+
1599+
# dialect: bigquery
1600+
STRING_AGG(DISTINCT tbl.str_col, ',' ORDER BY tbl.str_col);
1601+
STRING;
1602+
1603+
# dialect: bigquery
1604+
STRING_AGG(DISTINCT tbl.bin_col ORDER BY tbl.bin_col);
1605+
BINARY;
1606+
1607+
# dialect: bigquery
1608+
STRING_AGG(tbl.str_col, ',' LIMIT 10);
1609+
STRING;
1610+
1611+
# dialect: bigquery
1612+
STRING_AGG(tbl.str_col, ',' ORDER BY tbl.str_col LIMIT 10);
1613+
STRING;
1614+
1615+
# dialect: bigquery
1616+
STRING_AGG(DISTINCT tbl.str_col, ',' ORDER BY tbl.str_col LIMIT 10);
1617+
STRING;
1618+
1619+
# dialect: bigquery
1620+
STRING_AGG(DISTINCT tbl.bin_col ORDER BY tbl.bin_col LIMIT 10);
1621+
BINARY;
1622+
1623+
# dialect: bigquery
1624+
ARRAY_AGG(tbl.int_col LIMIT 10);
1625+
ARRAY<INT>;
1626+
1627+
# dialect: bigquery
1628+
ARRAY_AGG(DISTINCT tbl.str_col ORDER BY tbl.str_col LIMIT 10);
1629+
ARRAY<STRING>;
1630+
15911631
# dialect: bigquery
15921632
DATETIME_TRUNC(DATETIME "2008-12-25 15:30:00", DAY);
15931633
DATETIME;

0 commit comments

Comments
 (0)