vanzin commented on a change in pull request #26108: [SPARK-26154][SS]
Streaming left/right outer join should not return outer nulls for already
matched rows
URL: https://github.com/apache/spark/pull/26108#discussion_r338822804
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StreamingSymmetricHashJoinExec.scala
##########
@@ -270,20 +279,30 @@ case class StreamingSymmetricHashJoinExec(
// * Getting an iterator over the rows that have aged out on the left
side. These rows are
// candidates for being null joined. Note that to avoid doing two
passes, this iterator
// removes the rows from the state manager as they're processed.
- // * Checking whether the current row matches a key in the right side
state, and that key
- // has any value which satisfies the filter function when joined. If
it doesn't,
- // we know we can join with null, since there was never (including
this batch) a match
- // within the watermark period. If it does, there must have been a
match at some point, so
- // we know we can't join with null.
+ // * (state format version 1) Checking whether the current row matches
a key in the
+ // right side state, and that key has any value which satisfies the
filter function when
+ // joined. If it doesn't, we know we can join with null, since there
was never
+ // (including this batch) a match within the watermark period. If it
does, there must have
+ // been a match at some point, so we know we can't join with null.
+ // * (state format version 2) We found edge-case of above approach
which brings correctness
+ // issue, and had to take another approach (see SPARK-26154); now
Spark stores 'matched'
+ // flag along with row, which is set to true when there's any
matching row on the right.
+
def matchesWithRightSideState(leftKeyValue: UnsafeRowPair) = {
rightSideJoiner.get(leftKeyValue.key).exists { rightValue =>
postJoinFilter(joinedRow.withLeft(leftKeyValue.value).withRight(rightValue))
}
}
val removedRowIter = leftSideJoiner.removeOldState()
- val outerOutputIter = removedRowIter
- .filterNot(pair => matchesWithRightSideState(pair))
- .map(pair => joinedRow.withLeft(pair.value).withRight(nullRight))
+ val outerOutputIter = removedRowIter.filterNot { kvAndMatched =>
+ stateFormatVersion match {
+ case 1 => matchesWithRightSideState(
+ new UnsafeRowPair(kvAndMatched.key, kvAndMatched.value))
+ case 2 => kvAndMatched.matched
+ case _ => throw new IllegalStateException("Incorrect state format
version! " +
Review comment:
s/Incorrect/Invalid (or Unexpected).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]