Github user retronym commented on a diff in the pull request:
https://github.com/apache/spark/pull/11410#discussion_r55785695
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/OuterScopes.scala
---
@@ -39,4 +41,47 @@ object OuterScopes {
def addOuterScope(outer: AnyRef): Unit = {
outerScopes.putIfAbsent(outer.getClass.getName, outer)
}
+
+ def getOuterScope(innerCls: Class[_]): AnyRef = {
+ assert(innerCls.isMemberClass)
+ val outerClassName = innerCls.getDeclaringClass.getName
+ val outer = outerScopes.get(outerClassName)
+ if (outer == null) {
+ outerClassName match {
+ // If the outer class is generated by REPL, users don't need to
register it as it has
+ // only one instance and there is a way to retrieve it: get the
`$read` object, call the
+ // `INSTANCE()` method to get the single instance of class
`$read`. Then call `$iw()`
+ // method multiply times to get the single instance of the inner
most `$iw` class.
+ case REPLClass(baseClassName) =>
+ val objClass = Utils.classForName(baseClassName + "$")
+ val objInstance = objClass.getField("MODULE$").get(null)
+ val baseInstance =
objClass.getMethod("INSTANCE").invoke(objInstance)
+ val baseClass = Utils.classForName(baseClassName)
+
+ var getter = iwGetter(baseClass)
+ var obj = baseInstance
+ while (getter != null) {
+ obj = getter.invoke(obj)
+ getter = iwGetter(getter.getReturnType)
+ }
+
--- End diff --
Yes, this looks cleaner to me.
---
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]