|
17 | 17 | package org.apache.spark.sql.catalyst.expressions |
18 | 18 |
|
19 | 19 | 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} |
21 | 23 |
|
22 | 24 | class SubexpressionEliminationSuite extends SparkFunSuite { |
23 | 25 | test("Semantic equals and hash") { |
@@ -171,4 +173,19 @@ class SubexpressionEliminationSuite extends SparkFunSuite { |
171 | 173 | assert(equivalence.getAllEquivalentExprs.count(_.size > 1) == 0) |
172 | 174 | assert(equivalence.getAllEquivalentExprs.count(_.size == 1) == 3) // add, two, explode |
173 | 175 | } |
| 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 | + } |
174 | 191 | } |
0 commit comments