Skip to content

Commit 2525d1a

Browse files
committed
Add unit test for ToArrayOp with scalar subquery expression
1 parent 25330d5 commit 2525d1a

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

  • packages/bigframes/tests/unit/core/compile/sqlglot/expressions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SELECT
2+
[
3+
COALESCE(
4+
(
5+
SELECT
6+
COALESCE(SUM(bf_arr_reduce_uid), 0)
7+
FROM UNNEST(`float_list_col`) AS bf_arr_reduce_uid
8+
),
9+
0.0
10+
)
11+
] AS `arr_subquery_coalesce`
12+
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0`

packages/bigframes/tests/unit/core/compile/sqlglot/expressions/test_array_ops.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,14 @@ def test_to_array_op(scalar_types_df: bpd.DataFrame, snapshot):
104104

105105
sql = utils._apply_ops_to_sql(bf_df, list(ops_map.values()), list(ops_map.keys()))
106106
snapshot.assert_match(sql, "out.sql")
107+
108+
109+
def test_to_array_with_subquery_expression(repeated_types_df: bpd.DataFrame, snapshot):
110+
reduced = ops.ArrayReduceOp(agg_ops.SumOp()).as_expr("float_list_col")
111+
coalesced_reduced = ops.coalesce_op.as_expr(reduced, expression.const(0.0))
112+
array_expr = ops.ToArrayOp().as_expr(coalesced_reduced)
113+
114+
sql = utils._apply_ops_to_sql(
115+
repeated_types_df, [array_expr], ["arr_subquery_coalesce"]
116+
)
117+
snapshot.assert_match(sql, "out.sql")

0 commit comments

Comments
 (0)