ulysses-you commented on a change in pull request #29403:
URL: https://github.com/apache/spark/pull/29403#discussion_r496462601
##########
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)
Review comment:
After deep check some code, I found the magic.
1. we can get `FooEnum` class with default package using `mirror.
runtimeClass`.
2. we failed in `StaticInvoke` which will re-reflect the class if class name
end with `$`.
The `StaticInvoke` related code and pr
[#20753](https://github.com/apache/spark/pull/20753):
```
val objectName = staticObject.getName.stripSuffix("$")
val cls = if (staticObject.getName == objectName) {
staticObject
} else {
Utils.classForName(objectName)
}
```
I cann't find more comment about this code, seems we can use `staticObject`
directly instead of re-reflect it, is it ?
cc @kiszk
----------------------------------------------------------------
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]