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 @@ -422,8 +422,7 @@ case class WrapOption(child: Expression, optType: DataType)

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

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

override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val inputObject = child.genCode(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.expressions
import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import org.apache.spark.sql.catalyst.expressions.objects.{Invoke, UnwrapOption}
import org.apache.spark.sql.catalyst.expressions.objects._
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, GenericArrayData}
import org.apache.spark.sql.types.{IntegerType, ObjectType}

Expand Down Expand Up @@ -75,4 +75,13 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(unwrapObject, expected, InternalRow.fromSeq(Seq(input)))
}
}

test("SPARK-23586: WrapOption should support interpreted execution") {
val cls = ObjectType(classOf[java.lang.Integer])
val inputObject = BoundReference(0, cls, nullable = true)
val wrapObject = WrapOption(inputObject, cls)
Seq((1, Some(1)), (null, None)).foreach { case (input, expected) =>
checkEvaluation(wrapObject, expected, InternalRow.fromSeq(Seq(input)))
}
}
}