Skip to content

Commit 6aa4489

Browse files
restore logic to drop window order if not needed
1 parent 24fdb3a commit 6aa4489

File tree

21 files changed

+24
-87
lines changed

21 files changed

+24
-87
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def compile(
3333
right: typed_expr.TypedExpr,
3434
window: typing.Optional[window_spec.WindowSpec] = None,
3535
) -> sge.Expression:
36+
if op.order_independent and (window is not None) and window.is_unbounded:
37+
window = window.without_order()
3638
return BINARY_OP_REGISTRATION[op](op, left, right, window=window)
3739

3840

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def compile(
3030
op: agg_ops.WindowOp,
3131
window: typing.Optional[window_spec.WindowSpec] = None,
3232
) -> sge.Expression:
33+
if op.order_independent and (window is not None) and window.is_unbounded:
34+
window = window.without_order()
3335
return NULLARY_OP_REGISTRATION[op](op, window=window)
3436

3537

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def compile(
3636
column: typed_expr.TypedExpr,
3737
window: typing.Optional[window_spec.WindowSpec] = None,
3838
) -> sge.Expression:
39+
if op.order_independent and (window is not None) and window.is_unbounded:
40+
window = window.without_order()
3941
return UNARY_OP_REGISTRATION[op](op, column, window=window)
4042

4143

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def _select_to_cte(self) -> tuple[sge.Select, sge.Identifier]:
539539
cte_name = sge.to_identifier(
540540
next(self.uid_gen.get_uid_stream("bfcte_")), quoted=self.quoted
541541
)
542-
select_expr = self.expr._as_select().copy()
542+
select_expr = self._as_select().copy()
543543
select_expr, existing_ctes = _pop_query_ctes(select_expr)
544544
new_cte = sge.CTE(
545545
this=select_expr,
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
SELECT
2-
COALESCE(
3-
LOGICAL_AND(`bool_col`) OVER (
4-
ORDER BY `bool_col` ASC NULLS LAST
5-
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
6-
),
7-
TRUE
8-
) AS `agg_bool`
2+
COALESCE(LOGICAL_AND(`bool_col`) OVER (), TRUE) AS `agg_bool`
93
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
SELECT
2-
ANY_VALUE(`int64_col`) OVER (
3-
ORDER BY `int64_col` DESC
4-
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
5-
) AS `agg_int64`
2+
ANY_VALUE(`int64_col`) OVER () AS `agg_int64`
63
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
SELECT
2-
ANY_VALUE(`int64_col`) OVER (
3-
PARTITION BY `string_col`
4-
ORDER BY `int64_col` ASC NULLS LAST
5-
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
6-
) AS `agg_int64`
2+
ANY_VALUE(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64`
73
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
SELECT
2-
COALESCE(
3-
LOGICAL_OR(`bool_col`) OVER (
4-
ORDER BY `bool_col` ASC NULLS LAST
5-
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
6-
),
7-
FALSE
8-
) AS `agg_bool`
2+
COALESCE(LOGICAL_OR(`bool_col`) OVER (), FALSE) AS `agg_bool`
93
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
SELECT
2-
COUNT(`int64_col`) OVER (
3-
ORDER BY `int64_col` ASC NULLS LAST
4-
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
5-
) AS `agg_int64`
2+
COUNT(`int64_col`) OVER () AS `agg_int64`
63
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
SELECT
2-
COUNT(`int64_col`) OVER (
3-
PARTITION BY `string_col`
4-
ORDER BY `int64_col` DESC
5-
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
6-
) AS `agg_int64`
2+
COUNT(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64`
73
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`

0 commit comments

Comments
 (0)