Skip to content

Commit 4b9d0c9

Browse files
committed
UniqueKeyHashedRelation.get should return null if the value is null.
1 parent e0ebdd1 commit 4b9d0c9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ private[joins] final class GeneralHashedRelation(hashTable: JavaHashMap[Row, Com
4949
final class UniqueKeyHashedRelation(hashTable: JavaHashMap[Row, Row])
5050
extends HashedRelation with Serializable {
5151

52-
override def get(key: Row) = CompactBuffer(hashTable.get(key))
52+
override def get(key: Row) = {
53+
val v = hashTable.get(key)
54+
if (v eq null) null else CompactBuffer(v)
55+
}
5356

5457
def getValue(key: Row): Row = hashTable.get(key)
5558
}

sql/core/src/test/scala/org/apache/spark/sql/execution/joins/HashedRelationSuite.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class HashedRelationSuite extends FunSuite {
3737

3838
assert(hashed.get(data(0)) == CompactBuffer[Row](data(0)))
3939
assert(hashed.get(data(1)) == CompactBuffer[Row](data(1)))
40+
assert(hashed.get(Row(10)) === null)
4041

4142
val data2 = CompactBuffer[Row](data(2))
4243
data2 += data(2)
@@ -51,10 +52,12 @@ class HashedRelationSuite extends FunSuite {
5152
assert(hashed.get(data(0)) == CompactBuffer[Row](data(0)))
5253
assert(hashed.get(data(1)) == CompactBuffer[Row](data(1)))
5354
assert(hashed.get(data(2)) == CompactBuffer[Row](data(2)))
55+
assert(hashed.get(Row(10)) === null)
5456

5557
val uniqHashed = hashed.asInstanceOf[UniqueKeyHashedRelation]
5658
assert(uniqHashed.getValue(data(0)) == data(0))
5759
assert(uniqHashed.getValue(data(1)) == data(1))
5860
assert(uniqHashed.getValue(data(2)) == data(2))
61+
assert(uniqHashed.getValue(Row(10)) == null)
5962
}
6063
}

0 commit comments

Comments
 (0)