You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/03/15 07:48:47 UTC
[GitHub] [spark] cloud-fan commented on a change in pull request #31821: [SPARK-34729][SQL] Faster execution for broadcast nested loop join (left semi/anti with no condition)
cloud-fan commented on a change in pull request #31821:
URL: https://github.com/apache/spark/pull/31821#discussion_r594110622
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/joins/BroadcastNestedLoopJoinExec.scala
##########
@@ -193,124 +193,99 @@ case class BroadcastNestedLoopJoinExec(
}
/**
- * The implementation for these joins:
- *
- * LeftSemi with BuildRight
- * LeftAnti with BuildRight
+ * The implementation for LeftSemi and LeftAnti joins.
*/
private def leftExistenceJoin(
relation: Broadcast[Array[InternalRow]],
exists: Boolean): RDD[InternalRow] = {
- assert(buildSide == BuildRight)
- streamed.execute().mapPartitionsInternal { streamedIter =>
- val buildRows = relation.value
- val joinedRow = new JoinedRow
-
- if (condition.isDefined) {
- streamedIter.filter(l =>
- buildRows.exists(r => boundCondition(joinedRow(l, r))) == exists
- )
- } else if (buildRows.nonEmpty == exists) {
- streamedIter
- } else {
- Iterator.empty
- }
- }
- }
-
- private def existenceJoin(relation: Broadcast[Array[InternalRow]]): RDD[InternalRow] = {
- assert(buildSide == BuildRight)
- streamed.execute().mapPartitionsInternal { streamedIter =>
- val buildRows = relation.value
- val joinedRow = new JoinedRow
-
- if (condition.isDefined) {
- val resultRow = new GenericInternalRow(Array[Any](null))
- streamedIter.map { row =>
- val result = buildRows.exists(r => boundCondition(joinedRow(row, r)))
- resultRow.setBoolean(0, result)
- joinedRow(row, resultRow)
+ buildSide match {
+ case BuildRight =>
+ streamed.execute().mapPartitionsInternal { streamedIter =>
+ val buildRows = relation.value
+ val joinedRow = new JoinedRow
+
+ if (condition.isDefined) {
+ streamedIter.filter(l =>
+ buildRows.exists(r => boundCondition(joinedRow(l, r))) == exists
+ )
+ } else if (buildRows.nonEmpty == exists) {
+ streamedIter
+ } else {
+ Iterator.empty
+ }
}
- } else {
- val resultRow = new GenericInternalRow(Array[Any](buildRows.nonEmpty))
- streamedIter.map { row =>
- joinedRow(row, resultRow)
+ case BuildLeft if condition.isEmpty =>
+ // If condition is empty, do not need to read rows from streamed side at all.
+ // Only need to know whether streamed side is empty or not.
+ val streamExists = !streamed.execute().isEmpty()
Review comment:
shall we follow `Dataset.isEmpty` and call `streamed.executeTake(1).isEmpty`?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org