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_r341371357
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/SymmetricHashJoinStateManager.scala
##########
@@ -82,23 +88,47 @@ class SymmetricHashJoinStateManager(
}
/** Append a new value to the key */
- def append(key: UnsafeRow, value: UnsafeRow): Unit = {
+ def append(key: UnsafeRow, value: UnsafeRow, matched: Boolean): Unit = {
val numExistingValues = keyToNumValues.get(key)
- keyWithIndexToValue.put(key, numExistingValues, value)
+ keyWithIndexToValue.put(key, numExistingValues, value, matched)
keyToNumValues.put(key, numExistingValues + 1)
}
+ /**
+ * Get all the matched values for given join condition, with marking matched.
+ * This method is designed to mark joined rows properly without exposing
internal index of row.
+ */
+ def getJoinedRows(
+ key: UnsafeRow,
+ generateJoinedRow: InternalRow => JoinedRow,
+ predicate: JoinedRow => Boolean): Iterator[JoinedRow] = {
+ val numValues = keyToNumValues.get(key)
+ keyWithIndexToValue.getAll(key, numValues).map { keyIdxToValue =>
+ val joinedRow = generateJoinedRow(keyIdxToValue.value)
+ if (predicate(joinedRow)) {
+ if (!keyIdxToValue.matched) {
+ keyWithIndexToValue.put(key, keyIdxToValue.valueIndex,
keyIdxToValue.value,
+ matched = true)
+ }
+ joinedRow
+ } else {
+ null
+ }
+ }.filter(_ != null)
+ }
+
/**
* Remove using a predicate on keys.
*
- * This produces an iterator over the (key, value) pairs satisfying
condition(key), where the
- * underlying store is updated as a side-effect of producing next.
+ * This produces an iterator over the (key, value, matched) tuples
satisfying condition(key),
+ * where the underlying store is updated as a side-effect of producing next.
*
* This implies the iterator must be consumed fully without any other
operations on this manager
* or the underlying store being interleaved.
*/
- def removeByKeyCondition(removalCondition: UnsafeRow => Boolean):
Iterator[UnsafeRowPair] = {
- new NextIterator[UnsafeRowPair] {
+ def removeByKeyCondition(removalCondition: UnsafeRow => Boolean)
+ : Iterator[KeyToValuePair] = {
Review comment:
Fits in previous line.
----------------------------------------------------------------
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]