Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-10934][SQL] handle hashCode of unsafe array correctly #8987

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -285,7 +285,11 @@ public UnsafeMapData getMap(int ordinal) {

@Override
public int hashCode() {
return Murmur3_x86_32.hashUnsafeWords(baseObject, baseOffset, sizeInBytes, 42);
int result = 37;
for (int i = 0; i < sizeInBytes; i++) {
result += 37 * result + Platform.getByte(baseObject, baseOffset + i);
}
return result;
}

@Override
Expand Down
Expand Up @@ -131,4 +131,11 @@ class UnsafeRowSuite extends SparkFunSuite {
assert(emptyRow.getInt(0) === unsafeRow.getInt(0))
assert(emptyRow.getUTF8String(1) === unsafeRow.getUTF8String(1))
}

test("calling hashCode on unsafe array returned by getArray(ordinal)") {
val row = InternalRow.apply(new GenericArrayData(Array(1L)))
val unsafeRow = UnsafeProjection.create(Array[DataType](ArrayType(LongType))).apply(row)
// Makes sure hashCode on unsafe array won't crash
unsafeRow.getArray(0).hashCode()
}
}