ulysses-you commented on a change in pull request #29403:
URL: https://github.com/apache/spark/pull/29403#discussion_r496343571
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
##########
@@ -377,6 +378,29 @@ object ScalaReflection extends ScalaReflection {
expressions.Literal.create(null, ObjectType(cls)),
newInstance
)
+
+ case t if isSubtype(t, localTypeOf[Enumeration#Value]) =>
+ // package example
+ // object Foo extends Enumeration {
+ // type Foo = Value
+ // val E1, E2 = Value
+ // }
+ // the fullName of tpe is example.Foo.Foo, but we need example.Foo so
that
+ // we can call example.Foo.withName to deserialize string to
enumeration.
+ val className = t.asInstanceOf[TypeRef].pre.typeSymbol.asClass.fullName
+ // this check is for spark-shell which give a default package name
like '$line1.$read$$iw'
+ if (className.startsWith("$")) {
+ throw new UnsupportedOperationException(
+ s"Enumeration class required package name, but found $className")
+ }
+
+ val clazz = Utils.classForName(className)
+ StaticInvoke(
+ clazz,
+ ObjectType(getClassFromType(t)),
+ "withName",
+ createDeserializerForString(path, false) :: Nil,
+ returnNullable = false)
Review comment:
> What happens if you actually do operations on the null value stored as
an enum
We will get an exception, and the behavior is same as Java enum what we
supported.
```
case other if other.isEnum =>
createSerializerForString(
Invoke(inputObject, "name", ObjectType(classOf[String]),
returnNullable = false))
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]