@@ -461,7 +461,7 @@ case class BroadcastNestedLoopJoinExec(
461
461
}
462
462
463
463
private def codegenOuter (ctx : CodegenContext , input : Seq [ExprCode ]): String = {
464
- val (_ , buildRowArrayTerm) = prepareBroadcast(ctx)
464
+ val (buildRowArray , buildRowArrayTerm) = prepareBroadcast(ctx)
465
465
val (buildRow, checkCondition, _) = getJoinCondition(ctx, input, streamed, broadcast)
466
466
val buildVars = genBuildSideVars(ctx, buildRow, broadcast)
467
467
@@ -474,25 +474,33 @@ case class BroadcastNestedLoopJoinExec(
474
474
val foundMatch = ctx.freshName(" foundMatch" )
475
475
val numOutput = metricTerm(ctx, " numOutputRows" )
476
476
477
- s """
478
- |boolean $foundMatch = false;
479
- |for (int $arrayIndex = 0; $arrayIndex < $buildRowArrayTerm.length; $arrayIndex++) {
480
- | UnsafeRow $buildRow = (UnsafeRow) $buildRowArrayTerm[ $arrayIndex];
481
- | boolean $shouldOutputRow = false;
482
- | $checkCondition {
483
- | $shouldOutputRow = true;
484
- | $foundMatch = true;
485
- | }
486
- | if ( $arrayIndex == $buildRowArrayTerm.length - 1 && ! $foundMatch) {
487
- | $buildRow = null;
488
- | $shouldOutputRow = true;
489
- | }
490
- | if ( $shouldOutputRow) {
491
- | $numOutput.add(1);
492
- | ${consume(ctx, resultVars)}
493
- | }
494
- |}
495
- """ .stripMargin
477
+ if (buildRowArray.isEmpty) {
478
+ s """
479
+ |UnsafeRow $buildRow = null;
480
+ | $numOutput.add(1);
481
+ | ${consume(ctx, resultVars)}
482
+ """ .stripMargin
483
+ } else {
484
+ s """
485
+ |boolean $foundMatch = false;
486
+ |for (int $arrayIndex = 0; $arrayIndex < $buildRowArrayTerm.length; $arrayIndex++) {
487
+ | UnsafeRow $buildRow = (UnsafeRow) $buildRowArrayTerm[ $arrayIndex];
488
+ | boolean $shouldOutputRow = false;
489
+ | $checkCondition {
490
+ | $shouldOutputRow = true;
491
+ | $foundMatch = true;
492
+ | }
493
+ | if ( $arrayIndex == $buildRowArrayTerm.length - 1 && ! $foundMatch) {
494
+ | $buildRow = null;
495
+ | $shouldOutputRow = true;
496
+ | }
497
+ | if ( $shouldOutputRow) {
498
+ | $numOutput.add(1);
499
+ | ${consume(ctx, resultVars)}
500
+ | }
501
+ |}
502
+ """ .stripMargin
503
+ }
496
504
}
497
505
498
506
private def codegenLeftExistence (
0 commit comments