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

    https://github.com/apache/spark/pull/11826#discussion_r56788902
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/ShuffledHashJoin.scala
 ---
    @@ -55,11 +56,43 @@ case class ShuffledHashJoin(
       override def requiredChildDistribution: Seq[Distribution] =
         ClusteredDistribution(leftKeys) :: ClusteredDistribution(rightKeys) :: 
Nil
     
    +  private def buildHashedRelation(iter: Iterator[UnsafeRow]): 
HashedRelation = {
    +    // try to acquire some memory for the hash table, it could trigger 
other operator to free some
    +    // memory. The memory acquired here will mostly be used until the end 
of task.
    +    val context = TaskContext.get()
    +    val memoryManager = context.taskMemoryManager()
    +    var acquired = 0L
    +    var used = 0L
    +    context.addTaskCompletionListener((t: TaskContext) =>
    +      memoryManager.releaseExecutionMemory(acquired, MemoryMode.ON_HEAP, 
null)
    +    )
    +
    +    val copiedIter = iter.map { row =>
    +      // It's hard to guess what's exactly memory will be used, we have a 
raft guess here.
    +      // TODO: use BytesToBytesMap instead of HashMap for memory efficiency
    +      val needed = 150 + row.getSizeInBytes
    +      if (needed > acquired - used) {
    +        val got = memoryManager.acquireExecutionMemory(
    +          Math.max(memoryManager.pageSizeBytes(), needed), 
MemoryMode.ON_HEAP, null)
    +        if (got < needed) {
    +          throw new SparkException("Can't acquire enough memory to build 
hash map in shuffled" +
    +            "hash join, please use sort merge join by set 
spark.sql.join.preferSortMergeJoin=true")
    --- End diff --
    
    nit: typo set -> setting


---
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