[
https://issues.apache.org/jira/browse/FLINK-39677?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jim Hughes reassigned FLINK-39677:
----------------------------------
Assignee: Jim Hughes
> ARRAY_SORT fails at runtime with "Comparison method violates its general
> contract!" on arrays with duplicate elements
> ---------------------------------------------------------------------------------------------------------------------
>
> Key: FLINK-39677
> URL: https://issues.apache.org/jira/browse/FLINK-39677
> Project: Flink
> Issue Type: Bug
> Affects Versions: 1.20.4, 2.1.2, 2.0.2, 2.3.0, 2.2.1
> Reporter: Jim Hughes
> Assignee: Jim Hughes
> Priority: Major
>
> {{ArraySortFunction.ArraySortComparator.compare}} is built from a single SQL
> {{>}} evaluator and returns {{+1}} or {{-1}} based on the boolean result — it
> never returns {{0}}. For two equal elements {{a}} and {{b}}, both {{a > b}}
> and {{b > a}} are {{FALSE}}, so {{compare(a, b) == compare(b, a) == -1}}.
> This violates {{java.util.Comparator}}'s antisymmetry requirement.
> TimSort detects the contradiction once the array is large enough to take the
> merge path (≥32 elements with duplicates), throwing:
> {noformat}
> java.lang.IllegalArgumentException: Comparison method violates its general
> contract!
> at java.util.TimSort.mergeHi(TimSort.java:903)
> at java.util.Arrays.sort(Arrays.java:1234)
> at
> org.apache.flink.table.runtime.functions.scalar.ArraySortFunction.eval(ArraySortFunction.java:91)
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)