Skip to content

Commit 55fca3d

Browse files
committed
make ibis runable
1 parent 89afa5b commit 55fca3d

File tree

6 files changed

+75
-37
lines changed

6 files changed

+75
-37
lines changed

bigframes/core/compile/sqlglot/aggregations/unary_compiler.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,11 @@ def _cut_ops_w_intervals(
245245
value = sge.Struct(
246246
expressions=[
247247
sge.PropertyEQ(
248-
this=sge.Identifier(this="left_exclusive"), expression=left
248+
this=sge.Identifier(this="left_exclusive", quoted=True),
249+
expression=left,
249250
),
250251
sge.PropertyEQ(
251-
this=sge.Identifier(this="right_inclusive"),
252+
this=sge.Identifier(this="right_inclusive", quoted=True),
252253
expression=right,
253254
),
254255
]
@@ -257,10 +258,11 @@ def _cut_ops_w_intervals(
257258
value = sge.Struct(
258259
expressions=[
259260
sge.PropertyEQ(
260-
this=sge.Identifier(this="left_inclusive"), expression=left
261+
this=sge.Identifier(this="left_inclusive", quoted=True),
262+
expression=left,
261263
),
262264
sge.PropertyEQ(
263-
this=sge.Identifier(this="right_exclusive"),
265+
this=sge.Identifier(this="right_exclusive", quoted=True),
264266
expression=right,
265267
),
266268
]

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/out.sql renamed to tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins.sql

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ WITH `bfcte_0` AS (
44
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
55
), `bfcte_1` AS (
66
SELECT
7+
*,
78
CASE
89
WHEN `int64_col` <= MIN(`int64_col`) OVER () + (
910
1 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3)
@@ -46,36 +47,9 @@ WITH `bfcte_0` AS (
4647
3 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3)
4748
) + 0 AS `right_inclusive`
4849
)
49-
END AS `bfcol_1`,
50-
CASE
51-
WHEN `int64_col` > 0 AND `int64_col` <= 1
52-
THEN STRUCT(0 AS left_exclusive, 1 AS right_inclusive)
53-
WHEN `int64_col` > 1 AND `int64_col` <= 2
54-
THEN STRUCT(1 AS left_exclusive, 2 AS right_inclusive)
55-
END AS `bfcol_2`,
56-
CASE
57-
WHEN `int64_col` < MIN(`int64_col`) OVER () + (
58-
1 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3)
59-
)
60-
THEN 'a'
61-
WHEN `int64_col` < MIN(`int64_col`) OVER () + (
62-
2 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3)
63-
)
64-
THEN 'b'
65-
WHEN `int64_col` IS NOT NULL
66-
THEN 'c'
67-
END AS `bfcol_3`,
68-
CASE
69-
WHEN `int64_col` > 0 AND `int64_col` <= 1
70-
THEN 0
71-
WHEN `int64_col` > 1 AND `int64_col` <= 2
72-
THEN 1
73-
END AS `bfcol_4`
50+
END OVER () AS `bfcol_1`
7451
FROM `bfcte_0`
7552
)
7653
SELECT
77-
`bfcol_1` AS `int_bins`,
78-
`bfcol_2` AS `interval_bins`,
79-
`bfcol_3` AS `int_bins_labels`,
80-
`bfcol_4` AS `interval_bins_labels`
54+
`bfcol_1` AS `int_bins`
8155
FROM `bfcte_1`
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
), `bfcte_1` AS (
6+
SELECT
7+
*,
8+
CASE
9+
WHEN `int64_col` < MIN(`int64_col`) OVER () + (
10+
1 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3)
11+
)
12+
THEN 'a'
13+
WHEN `int64_col` < MIN(`int64_col`) OVER () + (
14+
2 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3)
15+
)
16+
THEN 'b'
17+
WHEN `int64_col` IS NOT NULL
18+
THEN 'c'
19+
END OVER () AS `bfcol_1`
20+
FROM `bfcte_0`
21+
)
22+
SELECT
23+
`bfcol_1` AS `int_bins_labels`
24+
FROM `bfcte_1`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
), `bfcte_1` AS (
6+
SELECT
7+
*,
8+
CASE
9+
WHEN `int64_col` > 0 AND `int64_col` <= 1
10+
THEN STRUCT(0 AS `left_exclusive`, 1 AS `right_inclusive`)
11+
WHEN `int64_col` > 1 AND `int64_col` <= 2
12+
THEN STRUCT(1 AS `left_exclusive`, 2 AS `right_inclusive`)
13+
END OVER () AS `bfcol_1`
14+
FROM `bfcte_0`
15+
)
16+
SELECT
17+
`bfcol_1` AS `interval_bins`
18+
FROM `bfcte_1`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
), `bfcte_1` AS (
6+
SELECT
7+
*,
8+
CASE
9+
WHEN `int64_col` > 0 AND `int64_col` <= 1
10+
THEN 0
11+
WHEN `int64_col` > 1 AND `int64_col` <= 2
12+
THEN 1
13+
END OVER () AS `bfcol_1`
14+
FROM `bfcte_0`
15+
)
16+
SELECT
17+
`bfcol_1` AS `interval_bins_labels`
18+
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/aggregations/test_unary_compiler.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ def test_cut(scalar_types_df: bpd.DataFrame, snapshot):
194194
expression.deref(col_name),
195195
),
196196
}
197-
sql = _apply_unary_agg_ops(
198-
bf_df, list(agg_ops_map.values()), list(agg_ops_map.keys())
199-
)
197+
window = window_spec.WindowSpec()
200198

201-
snapshot.assert_match(sql, "out.sql")
199+
# Loop through the aggregation map items
200+
for test_name, agg_expr in agg_ops_map.items():
201+
sql = _apply_unary_window_op(bf_df, agg_expr, window, test_name)
202+
203+
snapshot.assert_match(sql, f"{test_name}.sql")
202204

203205

204206
def test_dense_rank(scalar_types_df: bpd.DataFrame, snapshot):

0 commit comments

Comments
 (0)