Skip to content

Commit 5451adb

Browse files
committed
refactor: increase test coverages on sqlglot compiler
1 parent 0ebc733 commit 5451adb

File tree

37 files changed

+306
-89
lines changed

37 files changed

+306
-89
lines changed

bigframes/core/compile/sqlglot/aggregate_compiler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,5 @@ def compile_analytic(
7070
aggregate.arg.output_type,
7171
)
7272
return unary_compiler.compile(aggregate.op, column, window)
73-
elif isinstance(aggregate, agg_expressions.BinaryAggregation):
74-
raise NotImplementedError("binary analytic operations not yet supported")
7573
else:
7674
raise ValueError(f"Unexpected analytic operation: {aggregate}")

bigframes/core/compile/sqlglot/expressions/array_ops.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,6 @@ def _coerce_bool_to_int(typed_expr: TypedExpr) -> sge.Expression:
105105
return typed_expr.expr
106106

107107

108-
def _string_slice(expr: TypedExpr, op: ops.ArraySliceOp) -> sge.Expression:
109-
# local name for each element in the array
110-
el = sg.to_identifier("el")
111-
# local name for the index in the array
112-
slice_idx = sg.to_identifier("slice_idx")
113-
114-
conditions: typing.List[sge.Predicate] = [slice_idx >= op.start]
115-
if op.stop is not None:
116-
conditions.append(slice_idx < op.stop)
117-
118-
selected_elements = (
119-
sge.select(el)
120-
.from_(
121-
sge.Unnest(
122-
expressions=[expr.expr],
123-
alias=sge.TableAlias(columns=[el]),
124-
offset=slice_idx,
125-
)
126-
)
127-
.where(*conditions)
128-
)
129-
130-
return sge.array(selected_elements)
131-
132-
133108
def _array_slice(expr: TypedExpr, op: ops.ArraySliceOp) -> sge.Expression:
134109
# local name for each element in the array
135110
el = sg.to_identifier("el")
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
SELECT
2-
`string_list_col`[SAFE_OFFSET(1)] AS `string_list_col`
3-
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0`
2+
IF(SUBSTRING(`string_col`, 2, 1) <> '', SUBSTRING(`string_col`, 2, 1), NULL) AS `string_index`,
3+
[`int64_col`, `int64_too`][SAFE_OFFSET(1)] AS `array_index`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_reduce_op/out.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@ SELECT
1818
SELECT
1919
COALESCE(LOGICAL_OR(bf_arr_reduce_uid), FALSE)
2020
FROM UNNEST(`bool_list_col`) AS bf_arr_reduce_uid
21-
) AS `any_bool`
21+
) AS `any_bool`,
22+
(
23+
SELECT
24+
ARRAY_AGG(bf_arr_reduce_uid IGNORE NULLS)
25+
FROM UNNEST(`string_list_col`) AS bf_arr_reduce_uid
26+
) AS `array_agg_str`
2227
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SELECT
2+
SUBSTRING(`string_col`, 2, 4) AS `string_slice`,
3+
ARRAY(
4+
SELECT
5+
el
6+
FROM UNNEST([`int64_col`, `int64_too`]) AS el WITH OFFSET AS slice_idx
7+
WHERE
8+
slice_idx >= 1
9+
) AS `slice_only_start`,
10+
ARRAY(
11+
SELECT
12+
el
13+
FROM UNNEST([`int64_col`, `int64_too`]) AS el WITH OFFSET AS slice_idx
14+
WHERE
15+
slice_idx >= 1 AND slice_idx < 5
16+
) AS `slice_start_stop`
17+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_slice_with_only_start/out.sql

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_slice_with_start_and_stop/out.sql

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT
2+
OBJ.GET_ACCESS_URL(`string_col`, 'READ', INTERVAL 3600 MICROSECOND) AS `string_col`
3+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT
2+
OBJ.MAKE_REF(`string_col`) AS `string_col`
3+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_and_op/out.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ SELECT
44
`int64_col`,
55
`int64_col` & `int64_col` AS `int_and_int`,
66
`bool_col` AND `bool_col` AS `bool_and_bool`,
7-
IF(`bool_col` = FALSE, `bool_col`, NULL) AS `bool_and_null`
7+
IF(`bool_col` = FALSE, `bool_col`, NULL) AS `bool_and_null`,
8+
IF(`bool_col` = FALSE, `bool_col`, NULL) AS `null_and_bool`
89
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

0 commit comments

Comments
 (0)