c21 commented on a change in pull request #32528:
URL: https://github.com/apache/spark/pull/32528#discussion_r631690259
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/SortMergeJoinExec.scala
##########
@@ -679,60 +704,124 @@ case class SortMergeJoinExec(
(evaluateVariables(streamedVars), "")
}
- val thisPlan = ctx.addReferenceObj("plan", this)
- val eagerCleanup = s"$thisPlan.cleanupResources();"
-
- lazy val innerJoin =
+ val beforeLoop =
s"""
- |while (findNextJoinRows($streamedInput, $bufferedInput)) {
- | ${streamedVarDecl.mkString("\n")}
- | ${beforeLoop.trim}
- | scala.collection.Iterator<UnsafeRow> $iterator =
$matches.generateIterator();
- | while ($iterator.hasNext()) {
- | InternalRow $bufferedRow = (InternalRow) $iterator.next();
- | ${condCheck.trim}
- | $numOutput.add(1);
- | ${consume(ctx, resultVars)}
- | }
- | if (shouldStop()) return;
- |}
- |$eagerCleanup
- """.stripMargin
-
- lazy val outerJoin = {
- val hasOutputRow = ctx.freshName("hasOutputRow")
+ |${streamedVarDecl.mkString("\n")}
+ |${streamedBeforeLoop.trim}
+ |scala.collection.Iterator<UnsafeRow> $iterator =
$matches.generateIterator();
+ """.stripMargin
+ val outputRow =
s"""
- |while ($streamedInput.hasNext()) {
- | findNextJoinRows($streamedInput, $bufferedInput);
- | ${streamedVarDecl.mkString("\n")}
- | ${beforeLoop.trim}
- | scala.collection.Iterator<UnsafeRow> $iterator =
$matches.generateIterator();
- | boolean $hasOutputRow = false;
- |
- | // the last iteration of this loop is to emit an empty row if
there is no matched rows.
- | while ($iterator.hasNext() || !$hasOutputRow) {
- | InternalRow $bufferedRow = $iterator.hasNext() ?
- | (InternalRow) $iterator.next() : null;
- | ${condCheck.trim}
- | $hasOutputRow = true;
- | $numOutput.add(1);
- | ${consume(ctx, resultVars)}
- | }
- | if (shouldStop()) return;
- |}
- |$eagerCleanup
+ |$numOutput.add(1);
+ |${consume(ctx, resultVars)}
""".stripMargin
- }
+ val findNextJoinRows = s"findNextJoinRows($streamedInput, $bufferedInput)"
+ val thisPlan = ctx.addReferenceObj("plan", this)
+ val eagerCleanup = s"$thisPlan.cleanupResources();"
joinType match {
- case _: InnerLike => innerJoin
- case LeftOuter | RightOuter => outerJoin
+ case _: InnerLike =>
+ codegenInner(findNextJoinRows, beforeLoop, iterator, bufferedRow,
condCheck, outputRow,
Review comment:
Actually after double checking, we do not need to do `beforeLoop.trim`
as `beforeLoop` already has `stripMargin`, and has no trailing spaces. Also
updated to avoid repeated `conditionCheck.trim`
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]