Changes

Summary

  1. [SPARK-37037][SQL] Improve byte array sort by unify compareTo function (details)
Commit 74d974a5af998c7c40f97a164f7b0eba2ccd2d4e by srowen
[SPARK-37037][SQL] Improve byte array sort by unify compareTo function of UTF8String and ByteArray

### What changes were proposed in this pull request?

Unify the compare function of `UTF8String` and `ByteArray`.

### Why are the changes needed?

`BinaryType` use `TypeUtils.compareBinary` to compare two byte array, however it's slow since it compares byte array using unsigned int comparison byte by bye.

We can compare them using `Platform.getLong` with unsigned long comparison if they have more than 8 bytes. And here is some histroy about this `TODO` https://github.com/apache/spark/pull/6755/files#r32197461

The benchmark result should be same with `UTF8String`, can be found in https://github.com/apache/spark/pull/19180 (https://github.com/apache/spark/pull/19180#issuecomment-329467838)

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Move test from `TypeUtilsSuite` to `ByteArraySuite`

Closes #34310 from ulysses-you/SPARK-37037.

Authored-by: ulysses-you <ulyssesyou18@gmail.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
The file was addedsql/core/benchmarks/ByteArrayBenchmark-jdk11-results.txt
The file was modifiedsql/catalyst/src/main/scala/org/apache/spark/sql/types/BinaryType.scala (diff)
The file was modifiedsql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala (diff)
The file was modifiedcommon/unsafe/src/main/java/org/apache/spark/unsafe/types/ByteArray.java (diff)
The file was modifiedcommon/unsafe/src/test/java/org/apache/spark/unsafe/array/ByteArraySuite.java (diff)
The file was modifiedsql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala (diff)
The file was modifiedsql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/TypeUtilsSuite.scala (diff)
The file was addedsql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/ByteArrayBenchmark.scala
The file was modifiedcommon/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java (diff)
The file was addedsql/core/benchmarks/ByteArrayBenchmark-results.txt