Skip to content

Commit 3ae70e8

Browse files
committed
Add test.
1 parent 3274e91 commit 3ae70e8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/SubexpressionEliminationSuite.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.apache.spark.sql.catalyst.expressions
1818

1919
import org.apache.spark.SparkFunSuite
20-
import org.apache.spark.sql.types.IntegerType
20+
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateMutableProjection
21+
import org.apache.spark.sql.catalyst.expressions.objects.AssertNotNull
22+
import org.apache.spark.sql.types.{IntegerType, StructField, StructType}
2123

2224
class SubexpressionEliminationSuite extends SparkFunSuite {
2325
test("Semantic equals and hash") {
@@ -171,4 +173,19 @@ class SubexpressionEliminationSuite extends SparkFunSuite {
171173
assert(equivalence.getAllEquivalentExprs.count(_.size > 1) == 0)
172174
assert(equivalence.getAllEquivalentExprs.count(_.size == 1) == 3) // add, two, explode
173175
}
176+
177+
test("SPARK-18395: evaluate subexpressions like lazy variables") {
178+
val row = new GenericInternalRow(Seq(null, new java.lang.Integer(10)).toArray[Any])
179+
val bound = BoundReference(0, IntegerType, true)
180+
val add = Add(bound, Literal(1))
181+
val assertNotNull = AssertNotNull(bound, Seq.empty[String])
182+
val expr = If(
183+
IsNull(bound),
184+
Literal(1),
185+
Add(assertNotNull, Add(assertNotNull, Literal(1))))
186+
val schema = StructType(Seq(StructField("int", IntegerType))).toAttributes
187+
val projection =
188+
GenerateMutableProjection.generate(Seq(expr), schema, useSubexprElimination = true)
189+
projection(row).getInt(0)
190+
}
174191
}

0 commit comments

Comments
 (0)