Skip to content

Commit

Permalink
fix(backends): ensure that the order_by expressions order is preserve…
Browse files Browse the repository at this point in the history
…d when duplicates are introduced
  • Loading branch information
cpcloud committed Jan 8, 2024
1 parent 6f4caea commit 1082ea1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions ibis/backends/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,7 @@ def test_rank_followed_by_over_call_merge_frames(backend, alltypes, df):
raises=sa.exc.ProgrammingError,
)
@pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError)
@pytest.mark.notyet(["flink"], raises=com.UnsupportedOperationError)
@pytest.mark.broken(
["pyspark"], reason="pyspark requires CURRENT ROW", raises=PySparkAnalysisException
)
Expand Down
9 changes: 8 additions & 1 deletion ibis/expr/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@ def merge_windows(_, default_frame):
group_by = tuple(toolz.unique(_.frame.group_by + default_frame.group_by))

order_by = {}
for sort_key in _.frame.order_by + default_frame.order_by:
# iterate in the order of the existing keys followed by the new keys
#
# this allows duplicates to be overridden with no effect on the original
# position
#
# see https://github.com/ibis-project/ibis/issues/7940 for how this
# originally manifested
for sort_key in default_frame.order_by + _.frame.order_by:
order_by[sort_key.expr] = sort_key.ascending
order_by = tuple(ops.SortKey(k, v) for k, v in order_by.items())

Expand Down
1 change: 0 additions & 1 deletion ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,6 @@ def bind(table):
)
return expr

op = self.op()
if isinstance(window, bl.WindowBuilder):
if table := an.find_first_base_table(self.op()):
return bind(table)
Expand Down

0 comments on commit 1082ea1

Please sign in to comment.