viirya opened a new issue, #25556: URL: https://github.com/apache/datafusion/issues/25556
### Describe the bug ### Describe the bug `ScalarValue::partial_cmp` does not correctly compare `Map` values. Maps with identical keys but different values are currently considered equal. For example: ```rust map(["a"], [1]).partial_cmp(&map(["a"], [2])) ``` returns: ```rust Some(Ordering::Equal) ``` The expected result is: ```rust Some(Ordering::Less) ``` ### Root cause `partial_cmp_map` iterates over `MapArray::len()`. A `ScalarValue::Map` contains a single-element `MapArray`, so this loop runs once and compares only entry column 0—the keys. Entry column 1—the values—is ignored. Simply iterating over both entry columns would still be inconsistent with Arrow ordering because it would compare all keys before all values. Arrow compares maps lexicographically by `(key, value)` entry. ### Impact This can affect code paths that compare Map-backed `ScalarValue`s, including: - merging ordered `first_value` and `last_value` aggregate states - merging `nth_value` aggregate states - validating range-partition split points - detecting ordered aggregation boundaries across batches - direct users of `ScalarValue::partial_cmp` and `try_cmp` Results may depend on batch or partition boundaries when Map ordering keys have identical keys but different values. ### Expected behavior `ScalarValue::Map` comparison should use the same ordering semantics as Arrow sorting and nested comparisons, including: - both keys and values - lexicographic `(key, value)` entry ordering - entry count - null handling This keeps scalar comparison consistent with `SortExec`, nested comparison expressions, and Arrow's row encoding. ### To Reproduce _No response_ ### Expected behavior _No response_ ### Additional context _No response_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
