Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/12640#discussion_r61383378
--- Diff:
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeArrayData.java
---
@@ -336,4 +336,62 @@ public UnsafeArrayData copy() {
arrayCopy.pointTo(arrayDataCopy, Platform.BYTE_ARRAY_OFFSET,
sizeInBytes);
return arrayCopy;
}
+
+ public int[] toPrimitiveIntArray() {
--- End diff --
I didn't override the `toIntArray`, but create this special method instead.
This operation is dangerous, if some elements are null, we won't return 0, but
may crash instead. The reason is we don't write null values, if an element is
null, we simply mark it as null in the offset region and skip it. For example,
the data size of unsafe int array may be less than `4 * numElements` and the
memory copy may crash.
Ideally I think we need to improve unsafe array format to handle primitive
array better.
---
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]