Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1163#discussion_r14164580
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins.scala ---
    @@ -67,73 +62,72 @@ case class HashJoin(
       @transient lazy val streamSideKeyGenerator =
         () => new MutableProjection(streamedKeys, streamedPlan.output)
     
    -  def execute() = {
     
    -    buildPlan.execute().zipPartitions(streamedPlan.execute()) { 
(buildIter, streamIter) =>
    -      // TODO: Use Spark's HashMap implementation.
    -      val hashTable = new java.util.HashMap[Row, ArrayBuffer[Row]]()
    -      var currentRow: Row = null
    -
    -      // Create a mapping of buildKeys -> rows
    -      while (buildIter.hasNext) {
    -        currentRow = buildIter.next()
    -        val rowKey = buildSideKeyGenerator(currentRow)
    -        if(!rowKey.anyNull) {
    -          val existingMatchList = hashTable.get(rowKey)
    -          val matchList = if (existingMatchList == null) {
    -            val newMatchList = new ArrayBuffer[Row]()
    -            hashTable.put(rowKey, newMatchList)
    -            newMatchList
    -          } else {
    -            existingMatchList
    -          }
    -          matchList += currentRow.copy()
    +  def joinIterators(buildIter: Iterator[Row], streamIter: Iterator[Row]): 
Iterator[Row] = {
    +    // TODO: Use Spark's HashMap implementation.
    +
    +    val hashTable = new java.util.HashMap[Row, ArrayBuffer[Row]]()
    +    var currentRow: Row = null
    +
    +    // Create a mapping of buildKeys -> rows
    +    while (buildIter.hasNext) {
    +      currentRow = buildIter.next()
    +      val rowKey = buildSideKeyGenerator(currentRow)
    +      if(!rowKey.anyNull) {
    +        val existingMatchList = hashTable.get(rowKey)
    +        val matchList = if (existingMatchList == null) {
    +          val newMatchList = new ArrayBuffer[Row]()
    +          hashTable.put(rowKey, newMatchList)
    +          newMatchList
    +        } else {
    +          existingMatchList
             }
    +        matchList += currentRow.copy()
           }
    +    }
     
    -      new Iterator[Row] {
    -        private[this] var currentStreamedRow: Row = _
    -        private[this] var currentHashMatches: ArrayBuffer[Row] = _
    -        private[this] var currentMatchPosition: Int = -1
    +    new Iterator[Row] {
    +      private[this] var currentStreamedRow: Row = _
    +      private[this] var currentHashMatches: ArrayBuffer[Row] = _
    +      private[this] var currentMatchPosition: Int = -1
     
    -        // Mutable per row objects.
    -        private[this] val joinRow = new JoinedRow
    +      // Mutable per row objects.
    +      private[this] val joinRow = new JoinedRow
     
    -        private[this] val joinKeys = streamSideKeyGenerator()
    +      private[this] val joinKeys = streamSideKeyGenerator()
     
    -        override final def hasNext: Boolean =
    -          (currentMatchPosition != -1 && currentMatchPosition < 
currentHashMatches.size) ||
    +      override final def hasNext: Boolean =
    +        (currentMatchPosition != -1 && currentMatchPosition < 
currentHashMatches.size) ||
               (streamIter.hasNext && fetchNext())
     
    -        override final def next() = {
    -          val ret = joinRow(currentStreamedRow, 
currentHashMatches(currentMatchPosition))
    -          currentMatchPosition += 1
    -          ret
    -        }
    +      override final def next() = {
    +        val ret = joinRow(currentStreamedRow, 
currentHashMatches(currentMatchPosition))
    --- End diff --
    
    Just in case you didn't miss this. 


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to