Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/395#discussion_r11650568
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/joins.scala ---
@@ -165,36 +165,64 @@ case class BroadcastNestedLoopJoin(
def execute() = {
val broadcastedRelation =
sc.broadcast(broadcast.execute().map(_.copy()).collect().toIndexedSeq)
- val streamedPlusMatches = streamed.execute().mapPartitions {
streamedIter =>
- val matchedRows = new ArrayBuffer[Row]
- // TODO: Use Spark's BitSet.
- val includedBroadcastTuples = new
BitSet(broadcastedRelation.value.size)
- val joinedRow = new JoinedRow
-
- streamedIter.foreach { streamedRow =>
- var i = 0
- var matched = false
-
- while (i < broadcastedRelation.value.size) {
- // TODO: One bitset per partition instead of per row.
- val broadcastedRow = broadcastedRelation.value(i)
- if (boundCondition(joinedRow(streamedRow, broadcastedRow))) {
- matchedRows += buildRow(streamedRow ++ broadcastedRow)
- matched = true
- includedBroadcastTuples += i
- }
- i += 1
+ val streamedPlusMatches = joinType match {
+ case LeftSemi =>
+ streamed.execute().mapPartitions {
+ streamedIter =>
+ val matchedRows = new ArrayBuffer[Row]
--- End diff --
Since the logic is pretty simple here, it might be better to stream the
results though a custom iterator instead of buffering them all in memory. It
would also be good to do this match at a higher level, or even break this out
into its own operator so that we don't need to build tuple objects for no
reason.
---
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.
---