[
https://issues.apache.org/jira/browse/DRILL-5094?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15715846#comment-15715846
]
Laurent Goujon commented on DRILL-5094:
---------------------------------------
I think the issue is just because we are casting to an int the result from a
long substraction:
{noformat}
java> long IntPlusOne = 0x80000000L;
long IntPlusOne = 2147483648
java> long zero = 2 * IntPlusOne + 5;
long zero = 4294967301
java> long one = 2* IntPlusOne + 8;
long one = 4294967304
java> long two = 4 * IntPlusOne + 4;
long two = 8589934596
java> zero - one;
java.lang.Long res4 = -3
java> one - two;
java.lang.Long res5 = -4294967292
java> zero - two;
java.lang.Long res6 = -4294967295
java> (int) (zero - one);
java.lang.Integer res7 = -3
java> (int) (zero - two);
java.lang.Integer res8 = 1
java> (int) (one - two);
java.lang.Integer res9 = 4
{noformat}
Even if the method was not down-casting the substraction, it might cause issue
in some cases when the substraction creates an overflow. That's why it's
probably safer to rely on {{Long.compareTo()}}
> Assure Comparator to be transitive
> ----------------------------------
>
> Key: DRILL-5094
> URL: https://issues.apache.org/jira/browse/DRILL-5094
> Project: Apache Drill
> Issue Type: Bug
> Reporter: Chunhui Shi
> Assignee: Chunhui Shi
> Priority: Critical
> Labels: ready-to-commit
>
> In AssignmentCreator.java, one Comparator could break transitive attribute
> required for a Comparator implementation and the result is not correct.
> E.g. for:
> long IntPlusOne = 0x80000000L;
> [0]=2 * IntPlusOne + 5, [1] = 2* IntPlusOne + 8, [2] = 4 * IntPlusOne + 4,
> the compare results will be like:
> compare([0],[1]) = -3,
> compare([1],[2]) = 4,
> compare([0],[2]) = 1
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)