Skip to content

Commit ef9e8f3

Browse files
author
Davies Liu
committed
fix bug
1 parent 4fb0bc8 commit ef9e8f3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/joins/BroadcastHashJoin.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,14 @@ case class BroadcastHashJoin(
193193
val numOutput = metricTerm(ctx, "numOutputRows")
194194

195195
val checkCondition = if (condition.isDefined) {
196+
val expr = condition.get
197+
// evaluate the variables from build side that used by condition
198+
val eval = evaluateRequiredVariables(buildPlan.output, buildVars, expr.references)
196199
// filter the output via condition
197200
ctx.currentVars = input ++ buildVars
198-
val ev = BindReferences.bindReference(
199-
condition.get, streamedPlan.output ++ buildPlan.output).gen(ctx)
201+
val ev = BindReferences.bindReference(expr, streamedPlan.output ++ buildPlan.output).gen(ctx)
200202
s"""
203+
|$eval
201204
|${ev.code}
202205
|if (${ev.isNull} || !${ev.value}) continue;
203206
""".stripMargin
@@ -257,10 +260,11 @@ case class BroadcastHashJoin(
257260
// filter the output via condition
258261
val conditionPassed = ctx.freshName("conditionPassed")
259262
val checkCondition = if (condition.isDefined) {
260-
val eval = evaluateRequiredVariables(buildPlan.output, buildVars, condition.get.references)
263+
val expr = condition.get
264+
// evaluate the variables from build side that used by condition
265+
val eval = evaluateRequiredVariables(buildPlan.output, buildVars, expr.references)
261266
ctx.currentVars = input ++ buildVars
262-
val ev = BindReferences.bindReference(condition.get,
263-
streamedPlan.output ++ buildPlan.output).gen(ctx)
267+
val ev = BindReferences.bindReference(expr, streamedPlan.output ++ buildPlan.output).gen(ctx)
264268
s"""
265269
|boolean $conditionPassed = true;
266270
|${eval.trim}
@@ -285,7 +289,6 @@ case class BroadcastHashJoin(
285289
|UnsafeRow $matched = $anyNull ? null: (UnsafeRow)$relationTerm.getValue(${keyEv.value});
286290
|${checkCondition.trim}
287291
|if (!$conditionPassed) {
288-
| // reset to null
289292
| $matched = null;
290293
| // reset the variables those are already evaluated.
291294
| ${buildVars.filter(_.code == "").map(v => s"${v.isNull} = true;").mkString("\n")}

0 commit comments

Comments
 (0)