From 4b9d0c9a6674b195feeda753a80920fcb5a5727c Mon Sep 17 00:00:00 2001 From: Reynold Xin Date: Wed, 8 Oct 2014 17:46:33 -0700 Subject: [PATCH] UniqueKeyHashedRelation.get should return null if the value is null. --- .../apache/spark/sql/execution/joins/HashedRelation.scala | 5 ++++- .../spark/sql/execution/joins/HashedRelationSuite.scala | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala index cd43357f846cf..34d284cbefca0 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala @@ -49,7 +49,10 @@ private[joins] final class GeneralHashedRelation(hashTable: JavaHashMap[Row, Com final class UniqueKeyHashedRelation(hashTable: JavaHashMap[Row, Row]) extends HashedRelation with Serializable { - override def get(key: Row) = CompactBuffer(hashTable.get(key)) + override def get(key: Row) = { + val v = hashTable.get(key) + if (v eq null) null else CompactBuffer(v) + } def getValue(key: Row): Row = hashTable.get(key) } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/joins/HashedRelationSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/joins/HashedRelationSuite.scala index 871b7dcc6353e..2aad01ded1acf 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/joins/HashedRelationSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/joins/HashedRelationSuite.scala @@ -37,6 +37,7 @@ class HashedRelationSuite extends FunSuite { assert(hashed.get(data(0)) == CompactBuffer[Row](data(0))) assert(hashed.get(data(1)) == CompactBuffer[Row](data(1))) + assert(hashed.get(Row(10)) === null) val data2 = CompactBuffer[Row](data(2)) data2 += data(2) @@ -51,10 +52,12 @@ class HashedRelationSuite extends FunSuite { assert(hashed.get(data(0)) == CompactBuffer[Row](data(0))) assert(hashed.get(data(1)) == CompactBuffer[Row](data(1))) assert(hashed.get(data(2)) == CompactBuffer[Row](data(2))) + assert(hashed.get(Row(10)) === null) val uniqHashed = hashed.asInstanceOf[UniqueKeyHashedRelation] assert(uniqHashed.getValue(data(0)) == data(0)) assert(uniqHashed.getValue(data(1)) == data(1)) assert(uniqHashed.getValue(data(2)) == data(2)) + assert(uniqHashed.getValue(Row(10)) == null) } }