Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/8122#discussion_r36899421
--- Diff: unsafe/src/main/java/org/apache/spark/unsafe/types/ByteArray.java
---
@@ -29,4 +31,45 @@
public static void writeToMemory(byte[] src, Object target, long
targetOffset) {
Platform.copyMemory(src, Platform.BYTE_ARRAY_OFFSET, target,
targetOffset, src.length);
}
+
+ /**
+ * Returns a 64-bit integer that can be used as the prefix used in
sorting.
+ */
+ public static long getPrefix(byte[] bytes) {
+ if (bytes == null) {
+ return 0L;
+ } else {
+ final int minLen = Math.min(bytes.length, 8);
+ long p = 0;
+ for (int i = 0; i < minLen; ++i) {
+ p |= (128L + Platform.getByte(bytes, Platform.BYTE_ARRAY_OFFSET +
i))
+ << (56 - 8 * i);
+ }
+ return p;
+ }
+ }
+
+ public static byte[] subStringSQL(byte[] bytes, int pos, int len) {
+ // This pos calculation is according to UTF8String#subStringSQL
+ if (pos > bytes.length) {
+ return new byte[0];
--- End diff --
can we reuse an empty array?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]