File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed
bigframes/core/compile/sqlglot Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,15 @@ def get_window_order_by(
9797 ordering : typing .Tuple [ordering_spec .OrderingExpression , ...],
9898 override_null_order : bool = False ,
9999) -> typing .Optional [tuple [sge .Ordered , ...]]:
100- """Returns the SQL order by clause for a window specification."""
100+ """Returns the SQL order by clause for a window specification.
101+ Args:
102+ ordering (Tuple[ordering_spec.OrderingExpression, ...]):
103+ A tuple of ordering specification objects.
104+ override_null_order (bool):
105+ If True, overrides BigQuery's default null ordering behavior, which
106+ is sometimes incompatible with ordered aggregations. The generated SQL
107+ will include extra expressions to correctly enforce NULL FIRST/LAST.
108+ """
101109 if not ordering :
102110 return None
103111
@@ -110,8 +118,6 @@ def get_window_order_by(
110118 nulls_first = not ordering_spec_item .na_last
111119
112120 if override_null_order :
113- # Bigquery SQL considers NULLS to be "smallest" values, but we need
114- # to override in these cases.
115121 is_null_expr = sge .Is (this = expr , expression = sge .Null ())
116122 if nulls_first and desc :
117123 order_by .append (
Original file line number Diff line number Diff line change @@ -299,12 +299,8 @@ def compile_random_sample(
299299 def compile_aggregate (
300300 self , node : nodes .AggregateNode , child : ir .SQLGlotIR
301301 ) -> ir .SQLGlotIR :
302- # TODO: Update the notes
303- # Note that, when the window is range-bounded, we only need one ordering key.
304- # There are two reasons:
305- # 1. Manipulating null positions requires more than one ordering key, which
306- # is forbidden by SQL window syntax for range rolling.
307- # 2. Pandas does not allow range rolling on timeseries with nulls.
302+ # The BigQuery ordered aggregation cannot support for NULL FIRST/LAST,
303+ # so we need to add extra expressions to enforce the null ordering.
308304 ordering_cols = windows .get_window_order_by (
309305 node .order_by , override_null_order = True
310306 )
You can’t perform that action at this time.
0 commit comments