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

    https://github.com/apache/spark/pull/5717#discussion_r32891269
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/SortMergeJoin.scala
 ---
    @@ -82,86 +130,169 @@ case class SortMergeJoin(
     
             override final def next(): InternalRow = {
               if (hasNext) {
    -            // we are using the buffered right rows and run down left 
iterator
    -            val joinedRow = joinRow(leftElement, 
rightMatches(rightPosition))
    -            rightPosition += 1
    -            if (rightPosition >= rightMatches.size) {
    -              rightPosition = 0
    -              fetchLeft()
    -              if (leftElement == null || keyOrdering.compare(leftKey, 
matchKey) != 0) {
    -                stop = false
    -                rightMatches = null
    +            if (bufferedMatches == null || bufferedMatches.size == 0) {
    +              // we just found a row with no join match and we are here to 
produce a row
    +              // with this row and a standard null row from the other side.
    +              if (continueStreamed) {
    +                val joinedRow = smartJoinRow(streamedElement, 
bufferedNullRow)
    +                fetchStreamed()
    +                joinedRow
    +              } else {
    +                val joinedRow = smartJoinRow(streamedNullRow, 
bufferedElement)
    +                fetchBuffered()
    +                joinedRow
    +              }
    +            } else {
    +              // we are using the buffered right rows and run down left 
iterator
    +              val joinedRow = smartJoinRow(streamedElement, 
bufferedMatches(bufferedPosition))
    +              bufferedPosition += 1
    +              if (bufferedPosition >= bufferedMatches.size) {
    +                bufferedPosition = 0
    +                if (joinType != FullOuter || secondStreamedElement == 
null) {
    +                  fetchStreamed()
    --- End diff --
    
    I think we should use `boundCondition ` to update `bufferedMatches ` after 
we `fetchStreamed ()` .Otherwise we may get wrong answer.For example
    ```sql
    table a(key int,value int);table b(key int,value int)
    data of a
    1 3
    1 1
    2 1
    2 3
    
    data of b
    1 1
    2 1
    select a.key,b.key,a.value-b.value from a left outer join b on a.key=b.key 
and a.value - b.value > 1
    ```


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