Skip to content

Commit

Permalink
Reuse CompactBuffer in UniqueKeyHashedRelation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rxin committed Oct 9, 2014
1 parent 7fcffb5 commit 97626a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private[spark] class CompactBuffer[T] extends Seq[T] with Serializable {
}
}

private def update(position: Int, value: T): Unit = {
def update(position: Int, value: T): Unit = {
if (position < 0 || position >= curSize) {
throw new IndexOutOfBoundsException
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ import org.apache.spark.util.collection.CompactBuffer
* object.
*/
private[joins] sealed trait HashedRelation {
/**
* Get the rows matching the key back as a [[CompactBuffer]]. If no rows match this key,
* null is returned.
*
* The concrete implementation may reuse the returned [[CompactBuffer]].
*/
def get(key: Row): CompactBuffer[Row]
}

Expand All @@ -49,9 +55,16 @@ private[joins] final class GeneralHashedRelation(hashTable: JavaHashMap[Row, Com
private[joins] final class UniqueKeyHashedRelation(hashTable: JavaHashMap[Row, Row])
extends HashedRelation with Serializable {

private[this] val compactBuf = CompactBuffer[Row](null)

override def get(key: Row) = {
val v = hashTable.get(key)
if (v eq null) null else CompactBuffer(v)
if (v eq null) {
null
} else {
compactBuf(0) = v
compactBuf
}
}

def getValue(key: Row): Row = hashTable.get(key)
Expand Down

0 comments on commit 97626a1

Please sign in to comment.