Github user mridulm commented on a diff in the pull request: https://github.com/apache/spark/pull/22101#discussion_r209862610 --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/execution/RecordBinaryComparator.java --- @@ -42,16 +42,16 @@ public int compare( while ((leftOff + i) % 8 != 0 && i < leftLen) { res = (Platform.getByte(leftObj, leftOff + i) & 0xff) - (Platform.getByte(rightObj, rightOff + i) & 0xff); - if (res != 0) return res; + if (res != 0) return (int) res; i += 1; } } // for architectures that support unaligned accesses, chew it up 8 bytes at a time if (Platform.unaligned() || (((leftOff + i) % 8 == 0) && ((rightOff + i) % 8 == 0))) { while (i <= leftLen - 8) { - res = (int) ((Platform.getLong(leftObj, leftOff + i) - - Platform.getLong(rightObj, rightOff + i)) % Integer.MAX_VALUE); - if (res != 0) return res; + res = Platform.getLong(leftObj, leftOff + i) - + Platform.getLong(rightObj, rightOff + i); + if (res != 0) return res > 0 ? 1 : -1; --- End diff -- The subtraction is buggy due to potential overflow. Why not simply use: ``` final long v1 = Platform.getLong(leftObj, leftOff + i); final long v2 = Platform.getLong(rightObj, rightOff + i); if (v1 != v2) { return v1 > v2 ? -1 : 1; } ```
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org