Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()
}
}