Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit d654b74

Browse files
cloud-fanMatthewRBruce
authored andcommitted
[SPARK-21826][SQL] outer broadcast hash join should not throw NPE
This is a bug introduced by https://github.com/apache/spark/pull/11274/files#diff-7adb688cbfa583b5711801f196a074bbL274 . Non-equal join condition should only be applied when the equal-join condition matches. regression test Author: Wenchen Fan <[email protected]> Closes apache#19036 from cloud-fan/bug. (cherry picked from commit 2dd37d8) Signed-off-by: Herman van Hovell <[email protected]>
1 parent 2ee4660 commit d654b74

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ case class BroadcastHashJoinExec(
257257
s"""
258258
|boolean $conditionPassed = true;
259259
|${eval.trim}
260-
|${ev.code}
261260
|if ($matched != null) {
261+
| ${ev.code}
262262
| $conditionPassed = !${ev.isNull} && ${ev.value};
263263
|}
264264
""".stripMargin

sql/core/src/test/scala/org/apache/spark/sql/JoinSuite.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.spark.sql
1919

20+
import scala.collection.JavaConverters._
2021
import scala.collection.mutable.ListBuffer
2122
import scala.language.existentials
2223

@@ -25,6 +26,7 @@ import org.apache.spark.sql.catalyst.TableIdentifier
2526
import org.apache.spark.sql.execution.joins._
2627
import org.apache.spark.sql.internal.SQLConf
2728
import org.apache.spark.sql.test.SharedSQLContext
29+
import org.apache.spark.sql.types.StructType
2830
import org.apache.spark.TestUtils.{assertNotSpilled, assertSpilled}
2931

3032
class JoinSuite extends QueryTest with SharedSQLContext {
@@ -739,4 +741,22 @@ class JoinSuite extends QueryTest with SharedSQLContext {
739741
}
740742
}
741743
}
744+
745+
test("outer broadcast hash join should not throw NPE") {
746+
withTempView("v1", "v2") {
747+
withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "true") {
748+
Seq(2 -> 2).toDF("x", "y").createTempView("v1")
749+
750+
spark.createDataFrame(
751+
Seq(Row(1, "a")).asJava,
752+
new StructType().add("i", "int", nullable = false).add("j", "string", nullable = false)
753+
).createTempView("v2")
754+
755+
checkAnswer(
756+
sql("select x, y, i, j from v1 left join v2 on x = i and y < length(j)"),
757+
Row(2, 2, null, null)
758+
)
759+
}
760+
}
761+
}
742762
}

0 commit comments

Comments
 (0)