@@ -347,7 +347,8 @@ def _to_ibis_expr(
347347
348348 def filter (self , predicate : ex .Expression ) -> UnorderedIR :
349349 if any (map (is_window , map (self ._get_ibis_column , predicate .unbound_variables ))):
350- # ibis doesn't support qualify syntax
350+ # ibis doesn't support qualify syntax, so create CTE if filtering over window expression
351+ # https://github.com/ibis-project/ibis/issues/9775
351352 return self ._reproject_to_table ().filter (predicate )
352353 bindings = {col : self ._get_ibis_column (col ) for col in self .column_ids }
353354 condition = op_compiler .compile_expression (predicate , bindings )
@@ -791,6 +792,7 @@ def promote_offsets(self, col_id: str) -> OrderedIR:
791792 return expr_builder .build ()
792793 # Cannot nest analytic expressions, so reproject to cte first if needed.
793794 # Also ibis cannot window literals, so need to reproject those (even though this is legal in googlesql)
795+ # Seee: https://github.com/ibis-project/ibis/issues/9773
794796 can_directly_window = not any (
795797 map (lambda x : is_literal (x ) or is_window (x ), self ._ibis_order )
796798 )
@@ -828,6 +830,7 @@ def project_window_op(
828830 """
829831 # Cannot nest analytic expressions, so reproject to cte first if needed.
830832 # Also ibis cannot window literals, so need to reproject those (even though this is legal in googlesql)
833+ # See: https://github.com/ibis-project/ibis/issues/9773
831834 used_exprs = map (
832835 self ._get_any_column , [column_name , * window_spec .all_referenced_columns ]
833836 )
@@ -1058,7 +1061,8 @@ def _to_ibis_expr(
10581061
10591062 def filter (self , predicate : ex .Expression ) -> OrderedIR :
10601063 if any (map (is_window , map (self ._get_ibis_column , predicate .unbound_variables ))):
1061- # ibis doesn't support qualify syntax
1064+ # ibis doesn't support qualify syntax, so create CTE if filtering over window expression
1065+ # https://github.com/ibis-project/ibis/issues/9775
10621066 return self ._reproject_to_table ().filter (predicate )
10631067 bindings = {col : self ._get_ibis_column (col ) for col in self .column_ids }
10641068 condition = op_compiler .compile_expression (predicate , bindings )
0 commit comments