You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by sr...@apache.org on 2019/01/23 14:50:32 UTC

[spark] branch master updated: [SPARK-26681][SQL] Support Ammonite inner-class scopes.

This is an automated email from the ASF dual-hosted git repository.

srowen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new d008e23  [SPARK-26681][SQL] Support Ammonite inner-class scopes.
d008e23 is described below

commit d008e23ab50637ebe54eebe8784f5410f15486cc
Author: Ryan Blue <bl...@apache.org>
AuthorDate: Wed Jan 23 08:50:03 2019 -0600

    [SPARK-26681][SQL] Support Ammonite inner-class scopes.
    
    ## What changes were proposed in this pull request?
    
    This adds a new pattern to recognize Ammonite REPL classes and return the correct scope.
    
    ## How was this patch tested?
    
    Manually tested with Spark in an Ammonite session.
    
    Closes #23607 from rdblue/SPARK-26681-support-ammonite-scopes.
    
    Authored-by: Ryan Blue <bl...@apache.org>
    Signed-off-by: Sean Owen <se...@databricks.com>
---
 .../org/apache/spark/sql/catalyst/encoders/OuterScopes.scala   | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/OuterScopes.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/OuterScopes.scala
index a1f0312..665b2cd 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/OuterScopes.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/OuterScopes.scala
@@ -53,6 +53,12 @@ object OuterScopes {
     val outer = outerScopes.get(outerClassName)
     if (outer == null) {
       outerClassName match {
+        case AmmoniteREPLClass(cellClassName) =>
+          () => {
+            val objClass = Utils.classForName(cellClassName)
+            val objInstance = objClass.getField("MODULE$").get(null)
+            objClass.getMethod("instance").invoke(objInstance)
+          }
         // 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()`
@@ -95,4 +101,8 @@ object OuterScopes {
 
   // The format of REPL generated wrapper class's name, e.g. `$line12.$read$$iw$$iw`
   private[this] val REPLClass = """^(\$line(?:\d+)\.\$read)(?:\$\$iw)+$""".r
+
+  // The format of ammonite REPL generated wrapper class's name,
+  // e.g. `ammonite.$sess.cmd8$Helper$Foo` -> `ammonite.$sess.cmd8.instance.Foo`
+  private[this] val AmmoniteREPLClass = """^(ammonite\.\$sess\.cmd(?:\d+)\$).*""".r
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org