[
https://issues.apache.org/jira/browse/FLINK-40986?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated FLINK-40986:
-----------------------------------
Labels: pull-request-available (was: )
> Equal named Rows can have different hash values in PyFlink
> ----------------------------------------------------------
>
> Key: FLINK-40986
> URL: https://issues.apache.org/jira/browse/FLINK-40986
> Project: Flink
> Issue Type: Bug
> Components: API / Python
> Reporter: Biao Geng
> Priority: Minor
> Labels: pull-request-available
>
> h3. Problem
> Named PyFlink {{Row}} instances compare equal when their field names and
> corresponding values match, regardless of field order. However,
> {{Row._{_}hash{_}_}} hashes values in their original storage order.
> Consequently, equal rows can have different hashes, violating Python's
> equality/hash contract.
> This causes incorrect deduplication in Python sets and failed lookups or
> duplicate entries in Python dictionaries when equal named rows have different
> field orders.
> h3. Reproduce
> {code:python}
> from pyflink.common import Row
> left = Row(a=1, b=2)
> right = Row(b=2, a=1)
> print(left == right)
> print(hash(left) == hash(right))
> print(len({left, right}))
> print({left: "value"}.get(right, "NOT FOUND"))
> {code}
> Actual output:
> {code:java}
> True
> False
> 2
> NOT FOUND
> {code}
> Expected output:
> {code:java}
> True
> True
> 1
> value
> {code}
> h3. Root cause
> In {{{}flink-python/pyflink/common/types.py{}}}, {{Row._{_}eq{_}}}
> \{_}compares named-row values in sorted field-name order, while
> {{Row.}}{_}{{{}{_}hash{_}_{}}} hashes {{tuple(self)}} in the original value
> order.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)