Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.spark.sql.execution

import java.util.concurrent.TimeUnit._

import scala.collection.mutable
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration.Duration

Expand Down Expand Up @@ -171,13 +172,17 @@ case class FilterExec(condition: Expression, child: SparkPlan)
// This is very perf sensitive.
// TODO: revisit this. We can consider reordering predicates as well.
val generatedIsNotNullChecks = new Array[Boolean](notNullPreds.length)
val extraIsNotNullAttrs = mutable.Set[Attribute]()
val generated = otherPreds.map { c =>
val nullChecks = c.references.map { r =>
val idx = notNullPreds.indexWhere { n => n.asInstanceOf[IsNotNull].child.semanticEquals(r)}
if (idx != -1 && !generatedIsNotNullChecks(idx)) {
generatedIsNotNullChecks(idx) = true
// Use the child's output. The nullability is what the child produced.
genPredicate(notNullPreds(idx), input, child.output)
} else if (notNullAttributes.contains(r.exprId) && !extraIsNotNullAttrs.contains(r)) {
extraIsNotNullAttrs += r
genPredicate(IsNotNull(r), input, child.output)
} else {
""
}
Expand Down
26 changes: 26 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3233,6 +3233,32 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession {
}
}
}

test("SPARK-29213: FilterExec should not throw NPE") {
withTempView("t1", "t2", "t3") {
sql("SELECT ''").as[String].map(identity).toDF("x").createOrReplaceTempView("t1")
sql("SELECT * FROM VALUES 0, CAST(NULL AS BIGINT)")
.as[java.lang.Long]
.map(identity)
.toDF("x")
.createOrReplaceTempView("t2")
sql("SELECT ''").as[String].map(identity).toDF("x").createOrReplaceTempView("t3")
sql(
"""
|SELECT t1.x
|FROM t1
|LEFT JOIN (
| SELECT x FROM (
| SELECT x FROM t2
| UNION ALL
| SELECT SUBSTR(x,5) x FROM t3
| ) a
| WHERE LENGTH(x)>0
|) t3
|ON t1.x=t3.x
""".stripMargin).collect()
}
}
}

case class Foo(bar: Option[String])