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 @@ -459,9 +459,11 @@ private[execution] final class LongToUnsafeRowMap(val mm: TaskMemoryManager, cap
*/
def getValue(key: Long, resultRow: UnsafeRow): UnsafeRow = {
if (isDense) {
val idx = (key - minKey).toInt
if (idx >= 0 && key <= maxKey && array(idx) > 0) {
return getRow(array(idx), resultRow)
if (key >= minKey && key <= maxKey) {
val value = array((key - minKey).toInt)
if (value > 0) {
return getRow(value, resultRow)
}
}
} else {
var pos = firstSlot(key)
Expand Down Expand Up @@ -497,9 +499,11 @@ private[execution] final class LongToUnsafeRowMap(val mm: TaskMemoryManager, cap
*/
def get(key: Long, resultRow: UnsafeRow): Iterator[UnsafeRow] = {
if (isDense) {
val idx = (key - minKey).toInt
if (idx >=0 && key <= maxKey && array(idx) > 0) {
return valueIter(array(idx), resultRow)
if (key >= minKey && key <= maxKey) {
val value = array((key - minKey).toInt)
if (value > 0) {
return valueIter(value, resultRow)
}
}
} else {
var pos = firstSlot(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,51 @@ class HashedRelationSuite extends SparkFunSuite with SharedSQLContext {
}
}

test("LongToUnsafeRowMap with very wide range") {
val taskMemoryManager = new TaskMemoryManager(
new StaticMemoryManager(
new SparkConf().set("spark.memory.offHeap.enabled", "false"),
Long.MaxValue,
Long.MaxValue,
1),
0)
val unsafeProj = UnsafeProjection.create(Seq(BoundReference(0, LongType, false)))

{
// SPARK-16740
val keys = Seq(0L, Long.MaxValue, Long.MaxValue)
val map = new LongToUnsafeRowMap(taskMemoryManager, 1)
keys.foreach { k =>
map.append(k, unsafeProj(InternalRow(k)))
}
map.optimize()
val row = unsafeProj(InternalRow(0L)).copy()
keys.foreach { k =>
assert(map.getValue(k, row) eq row)
assert(row.getLong(0) === k)
}
map.free()
}


{
// SPARK-16802
val keys = Seq(Long.MaxValue, Long.MaxValue - 10)
val map = new LongToUnsafeRowMap(taskMemoryManager, 1)
keys.foreach { k =>
map.append(k, unsafeProj(InternalRow(k)))
}
map.optimize()
val row = unsafeProj(InternalRow(0L)).copy()
keys.foreach { k =>
assert(map.getValue(k, row) eq row)
assert(row.getLong(0) === k)
}
assert(map.getValue(Long.MinValue, row) eq null)
map.free()
}
}

test("Spark-14521") {
val ser = new KryoSerializer(
(new SparkConf).set("spark.kryo.referenceTracking", "false")).newInstance()
Expand Down