Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/7480#discussion_r35243775
--- Diff:
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java
---
@@ -405,7 +406,50 @@ public void writeToStream(OutputStream out, byte[]
writeBuffer) throws IOExcepti
}
@Override
+ public int hashCode() {
+ return Murmur3_x86_32.hashUnsafeWords(baseObject, baseOffset,
sizeInBytes, 42);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof UnsafeRow) {
+ UnsafeRow o = (UnsafeRow) other;
+ return (sizeInBytes == o.sizeInBytes) &&
+ ByteArrayMethods.arrayEquals(baseObject, baseOffset, o.baseObject,
o.baseOffset,
+ sizeInBytes);
+ }
+ return false;
+ }
+
+ /**
+ * Returns the underlying bytes for this UnsafeRow.
+ */
+ public byte[] getBytes() {
+ if (baseObject instanceof byte[] && baseOffset ==
PlatformDependent.BYTE_ARRAY_OFFSET
+ && (((byte[]) baseObject).length == sizeInBytes)) {
+ return (byte[]) baseObject;
+ } else {
+ byte[] bytes = new byte[sizeInBytes];
+ PlatformDependent.copyMemory(baseObject, baseOffset, bytes,
+ PlatformDependent.BYTE_ARRAY_OFFSET, sizeInBytes);
+ return bytes;
+ }
+ }
+
+ // This is for debugging
+ @Override
+ public String toString() {
+ StringBuilder build = new StringBuilder("[");
+ for (int i = 0; i < sizeInBytes; i += 8) {
+ build.append(PlatformDependent.UNSAFE.getLong(baseObject, baseOffset
+ i));
+ build.append(',');
+ }
+ build.append(']');
+ return build.toString();
+ }
+
+ @Override
public boolean anyNull() {
- return BitSetMethods.anySet(baseObject, baseOffset,
bitSetWidthInBytes);
+ return BitSetMethods.anySet(baseObject, baseOffset, bitSetWidthInBytes
/ 8);
--- End diff --
can you add a unit test for this? i'd imagine it affects correctness
---
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]