Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/11410#discussion_r54570439
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/OuterScopes.scala
---
@@ -39,4 +41,35 @@ object OuterScopes {
def addOuterScope(outer: AnyRef): Unit = {
outerScopes.putIfAbsent(outer.getClass.getName, outer)
}
+
+ def getOuterScope(innerCls: Class[_]): AnyRef = {
+ assert(innerCls.isMemberClass)
+ val outerCls = innerCls.getDeclaringClass.getName
+ val outer = outerScopes.get(outerCls)
+ if (outer == null) {
+ outerCls match {
+ case REPLClass(line) =>
+ val loader = Utils.getContextOrSparkClassLoader
+ def loadCls(clsName: String): Class[_] = Class.forName(clsName,
true, loader)
+
+ val cls1 = loadCls(line + "$read$")
+ val obj1 = cls1.getField("MODULE$").get(null)
+
+ val obj2 = cls1.getMethod("INSTANCE").invoke(obj1)
+ val cls2 = loadCls(line + "$read")
+
+ val obj3 = cls2.getMethod("$iw").invoke(obj2)
+ val cls3 = loadCls(line + "$read$$iw")
+
+ cls3.getMethod("$iw").invoke(obj3)
+
+ case _ => null
+ }
+ } else {
+ outer
+ }
+ }
+
+ // The format of REPL generated wrapper class's name, e.g.
`$line12.$read$$iw$$iw`
--- End diff --
If there are more than 2 nested `$iw` classes, can I call `$iw` method
multiple times to get the singleton of the inner-most `$iw` class? e.g. `obj`
is the singleton of `$line3.$read` class, can I use
`obj.$iw().$iw().$iw().$iw()` to get the singleton of inner most `$iw` class?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]