Skip to content

Commit f6b49f9

Browse files
mgaido91hvanhovell
authored andcommitted
[SPARK-23586][SQL] Add interpreted execution to WrapOption
## What changes were proposed in this pull request? The PR adds interpreted execution to WrapOption. ## How was this patch tested? added UT Author: Marco Gaido <[email protected]> Closes #20741 from mgaido91/SPARK-23586_2.
1 parent 7706eea commit f6b49f9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ case class WrapOption(child: Expression, optType: DataType)
422422

423423
override def inputTypes: Seq[AbstractDataType] = optType :: Nil
424424

425-
override def eval(input: InternalRow): Any =
426-
throw new UnsupportedOperationException("Only code-generated evaluation is supported")
425+
override def eval(input: InternalRow): Any = Option(child.eval(input))
427426

428427
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
429428
val inputObject = child.genCode(ctx)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.expressions
2020
import org.apache.spark.SparkFunSuite
2121
import org.apache.spark.sql.catalyst.InternalRow
2222
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
23-
import org.apache.spark.sql.catalyst.expressions.objects.{Invoke, UnwrapOption}
23+
import org.apache.spark.sql.catalyst.expressions.objects._
2424
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, GenericArrayData}
2525
import org.apache.spark.sql.types.{IntegerType, ObjectType}
2626

@@ -75,4 +75,13 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
7575
checkEvaluation(unwrapObject, expected, InternalRow.fromSeq(Seq(input)))
7676
}
7777
}
78+
79+
test("SPARK-23586: WrapOption should support interpreted execution") {
80+
val cls = ObjectType(classOf[java.lang.Integer])
81+
val inputObject = BoundReference(0, cls, nullable = true)
82+
val wrapObject = WrapOption(inputObject, cls)
83+
Seq((1, Some(1)), (null, None)).foreach { case (input, expected) =>
84+
checkEvaluation(wrapObject, expected, InternalRow.fromSeq(Seq(input)))
85+
}
86+
}
7887
}

0 commit comments

Comments
 (0)