Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[SPARK-23586][SQL] Add interpreted execution to WrapOption
  • Loading branch information
mgaido91 committed Mar 5, 2018
commit a67db05d2c1223af7d920cdcef0cd1aaf8bd329b
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,14 @@ 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 unwrapObject = WrapOption(inputObject, cls)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: unwrapObject?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem :)

unwrapObject.resolved
Seq((1, Some(1)), (null, None)).foreach { case (input, expected) =>
checkEvaluation(unwrapObject, expected, InternalRow.fromSeq(Seq(input)))
}
}
}