Skip to content

Commit 736625b

Browse files
committed
[SPARK-25690][SQL] Analyzer rule HandleNullInputsForUDF does not stabilize and can be applied infinitely
1 parent faf73dc commit 736625b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ class Analyzer(
21512151
// TODO: skip null handling for not-nullable primitive inputs after we can completely
21522152
// trust the `nullable` information.
21532153
val inputsNullCheck = nullableTypes.zip(inputs)
2154-
.filter { case (nullable, _) => !nullable }
2154+
.filter { case (nullable, expr) => !nullable && !expr.isInstanceOf[KnownNotNull] }
21552155
.map { case (_, expr) => IsNull(expr) }
21562156
.reduceLeftOption[Expression]((e1, e2) => Or(e1, e2))
21572157
// Once we add an `If` check above the udf, it is safe to mark those checked inputs

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ class AnalysisSuite extends AnalysisTest with Matchers {
351351
test("SPARK-24891 Fix HandleNullInputsForUDF rule") {
352352
val a = testRelation.output(0)
353353
val func = (x: Int, y: Int) => x + y
354-
val udf1 = ScalaUDF(func, IntegerType, a :: a :: Nil)
355-
val udf2 = ScalaUDF(func, IntegerType, a :: udf1 :: Nil)
354+
val udf1 = ScalaUDF(func, IntegerType, a :: a :: Nil, nullableTypes = false :: false :: Nil)
355+
val udf2 = ScalaUDF(func, IntegerType, a :: udf1 :: Nil, nullableTypes = false :: false :: Nil)
356356
val plan = Project(Alias(udf2, "")() :: Nil, testRelation)
357357
comparePlans(plan.analyze, plan.analyze.analyze)
358358
}

0 commit comments

Comments
 (0)