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 @@ -158,6 +158,7 @@ object Literal {
Literal(CatalystTypeConverters.createToCatalystConverter(dataType)(v), dataType)
case _: DayTimeIntervalType if v.isInstanceOf[Duration] =>
Literal(CatalystTypeConverters.createToCatalystConverter(dataType)(v), dataType)
case _: ObjectType => Literal(v, dataType)
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we do some assertion here? e.g. v.getClass should be or a sub-class of ObjectType.cls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shall we do some assertion here? e.g. v.getClass should be or a sub-class of ObjectType.cls

Already have a check in Literal.validateLiteralValue(value, dataType) when constructing Literal

case _ => Literal(CatalystTypeConverters.convertToCatalyst(v), dataType)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
import org.apache.spark.sql.types.DayTimeIntervalType._
import org.apache.spark.sql.types.YearMonthIntervalType._
import org.apache.spark.unsafe.types.CalendarInterval
import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String}

class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {

Expand Down Expand Up @@ -465,4 +465,10 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(Literal.create(duration, dt), result)
}
}

test("SPARK-37967: Literal.create support ObjectType") {
checkEvaluation(
Literal.create(UTF8String.fromString("Spark SQL"), ObjectType(classOf[UTF8String])),
UTF8String.fromString("Spark SQL"))
}
}