Skip to content

Commit aec74f0

Browse files
[Data] Fix AliasExpr structural equality to respect rename flag (ray-project#60711)
## Description This PR fixes a bug in AliasExpr.structurally_equals where the rename marker was always treated as equal, causing incorrect structural equality results. This could affect logical optimization rules that rely on accurate expression equivalence (e.g., projection pushdown). Main changes: Correct comparison of _is_rename against other._is_rename ## Related issues > Link related issues: "Fixes ray-project#1234", "Closes ray-project#1234", or "Related to ray-project#1234". ## Additional information > Optional: Add implementation details, API changes, usage examples, screenshots, etc. <!-- BUGBOT_STATUS --><sup><a href="https://cursor.com/dashboard?tab=bugbot">Cursor Bugbot</a> is reviewing your changes for commit <u>9a399ac</u></sup><!-- /BUGBOT_STATUS --> --------- Signed-off-by: slfan1989 <slfan1989@apache.org> Co-authored-by: Goutam <goutam@anyscale.com>
1 parent 4c76792 commit aec74f0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

python/ray/data/expressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ def structurally_equals(self, other: Any) -> bool:
13561356
isinstance(other, AliasExpr)
13571357
and self.expr.structurally_equals(other.expr)
13581358
and self.name == other.name
1359-
and self._is_rename == self._is_rename
1359+
and self._is_rename == other._is_rename
13601360
)
13611361

13621362

python/ray/data/tests/unit/expressions/test_core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ def test_alias_structural_equality(self, expr1, expr2, expected):
259259
"""Test structural equality for alias expressions."""
260260
assert expr1.structurally_equals(expr2) is expected
261261

262+
def test_alias_structural_equality_respects_rename_flag(self):
263+
expr = col("a")
264+
aliased = expr.alias("b")
265+
renamed = expr._rename("b")
266+
267+
assert aliased.structurally_equals(aliased)
268+
assert renamed.structurally_equals(renamed)
269+
assert not aliased.structurally_equals(renamed)
270+
assert not aliased.structurally_equals(expr.alias("c"))
271+
262272
def test_alias_evaluation_equivalence(self):
263273
"""Test that alias evaluation produces same result as original."""
264274
import pandas as pd

0 commit comments

Comments
 (0)