diff --git a/ibis/expr/rewrites.py b/ibis/expr/rewrites.py index cf6e40eb5fac..3b9d6760ce41 100644 --- a/ibis/expr/rewrites.py +++ b/ibis/expr/rewrites.py @@ -223,7 +223,7 @@ def lower_stringslice(_, **kwargs): @replace(p.Analytic) -def project_wrap_analytic(_, rel): +def wrap_analytic(_, **__): # Wrap analytic functions in a window function return ops.WindowFunction(_) @@ -250,7 +250,7 @@ def rewrite_project_input(value, relation): # or scalar subqueries depending on whether they are originating from the # relation return value.replace( - project_wrap_analytic | project_wrap_reduction, + wrap_analytic | project_wrap_reduction, filter=p.Value & ~p.WindowFunction, context={"rel": relation}, ) @@ -272,7 +272,9 @@ def filter_wrap_reduction(_): def rewrite_filter_input(value): - return value.replace(filter_wrap_reduction, filter=p.Value & ~p.WindowFunction) + return value.replace( + wrap_analytic | filter_wrap_reduction, filter=p.Value & ~p.WindowFunction + ) @replace(p.Analytic | p.Reduction) diff --git a/ibis/expr/tests/test_newrels.py b/ibis/expr/tests/test_newrels.py index 7fb6701c7357..34f76ae7763e 100644 --- a/ibis/expr/tests/test_newrels.py +++ b/ibis/expr/tests/test_newrels.py @@ -1829,3 +1829,12 @@ def test_expr_in_join_projection(): "lit6": "int64", } ) + + +def test_analytic_dereference(): + t = ibis.table({"a": "int"}) + ix = ibis.row_number() + expr = t.mutate(ix=ix).filter(ix == 5) + assert expr.op().predicates == ( + ops.Equals(ops.WindowFunction(ops.RowNumber()), ops.Literal(5, dtype="int8")), + )