Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8174#discussion_r37030902
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala
 ---
    @@ -247,40 +247,67 @@ private[joins] final class UnsafeHashedRelation(
       }
     
       override def writeExternal(out: ObjectOutput): Unit = 
Utils.tryOrIOException {
    -    out.writeInt(hashTable.size())
    -
    -    val iter = hashTable.entrySet().iterator()
    -    while (iter.hasNext) {
    -      val entry = iter.next()
    -      val key = entry.getKey
    -      val values = entry.getValue
    -
    -      // write all the values as single byte array
    -      var totalSize = 0L
    -      var i = 0
    -      while (i < values.length) {
    -        totalSize += values(i).getSizeInBytes + 4 + 4
    -        i += 1
    +    if (binaryMap != null) {
    +      // This could happen when a cached broadcast object need to be 
dumped into disk to free memory
    +      out.writeInt(binaryMap.numElements())
    +
    +      var buffer = new Array[Byte](64)
    +      def write(addr: MemoryLocation, length: Int): Unit = {
    +        if (buffer.length < length) {
    +          buffer = new Array[Byte](length)
    +        }
    +        Platform.copyMemory(addr.getBaseObject, addr.getBaseOffset,
    +          buffer, Platform.BYTE_ARRAY_OFFSET, length)
    +        out.write(buffer, 0, length)
           }
    -      assert(totalSize < Integer.MAX_VALUE, "values are too big")
    -
    -      // [key size] [values size] [key bytes] [values bytes]
    -      out.writeInt(key.getSizeInBytes)
    -      out.writeInt(totalSize.toInt)
    -      out.write(key.getBytes)
    -      i = 0
    -      while (i < values.length) {
    -        // [num of fields] [num of bytes] [row bytes]
    -        // write the integer in native order, so they can be read by 
UNSAFE.getInt()
    -        if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
    -          out.writeInt(values(i).numFields())
    -          out.writeInt(values(i).getSizeInBytes)
    -        } else {
    -          out.writeInt(Integer.reverseBytes(values(i).numFields()))
    -          out.writeInt(Integer.reverseBytes(values(i).getSizeInBytes))
    +
    +      val iter = binaryMap.iterator()
    +      while (iter.hasNext) {
    +        val loc = iter.next()
    +        // [key size] [values size] [key bytes] [values bytes]
    +        out.writeInt(loc.getKeyLength)
    +        out.writeInt(loc.getValueLength)
    +        write(loc.getKeyAddress, loc.getKeyLength)
    +        write(loc.getValueAddress, loc.getValueLength)
    --- End diff --
    
    Yes


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to