Skip to content

Commit d05c9ee

Browse files
Chip Senkbeilpwendell
authored andcommitted
[SPARK-4923][REPL] Add Developer API to REPL to allow re-publishing the REPL jar
As requested in [SPARK-4923](https://issues.apache.org/jira/browse/SPARK-4923), I've provided a rough DeveloperApi for the repl. I've only done this for Scala 2.10 because it does not appear that Scala 2.11 is implemented. The Scala 2.11 repl still has the old `scala.tools.nsc` package and the SparkIMain does not appear to have the class server needed for shipping code over (unless this functionality has been moved elsewhere?). I also left alone the `ExecutorClassLoader` and `ConstructorCleaner` as I have no experience working with those classes. This marks the majority of methods in `SparkIMain` as _private_ with a few special cases being _private[repl]_ as other classes within the same package access them. Any public method has been marked with `DeveloperApi` as suggested by pwendell and I took the liberty of writing up a Scaladoc for each one to further elaborate their usage. As the Scala 2.11 REPL [conforms]((scala/scala#2206)) to [JSR-223](http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/), the [Spark Kernel](https://github.com/ibm-et/spark-kernel) uses the SparkIMain of Scala 2.10 in the same manner. So, I've taken care to expose methods predominately related to necessary functionality towards a JSR-223 scripting engine implementation. 1. The ability to _get_ variables from the interpreter (and other information like class/symbol/type) 2. The ability to _put_ variables into the interpreter 3. The ability to _compile_ code 4. The ability to _execute_ code 5. The ability to get contextual information regarding the scripting environment Additional functionality that I marked as exposed included the following: 1. The blocking initialization method (needed to actually start SparkIMain instance) 2. The class server uri (needed to set the _spark.repl.class.uri_ property after initialization), reduced from the entire class server 3. The class output directory (beneficial for tools like ours that need to inspect and use the directory where class files are served) 4. Suppression (quiet/silence) mechanics for output 5. Ability to add a jar to the compile/runtime classpath 6. The reset/close functionality 7. Metric information (last variable assignment, "needed" for extracting results from last execution, real variable name for better debugging) 8. Execution wrapper (useful to have, but debatable) Aside from `SparkIMain`, I updated other classes/traits and their methods in the _repl_ package to be private/package protected where possible. A few odd cases (like the SparkHelper being in the scala.tools.nsc package to expose a private variable) still exist, but I did my best at labelling them. `SparkCommandLine` has proven useful to extract settings and `SparkJLineCompletion` has proven to be useful in implementing auto-completion in the [Spark Kernel](https://github.com/ibm-et/spark-kernel) project. Other than those - and `SparkIMain` - my experience has yielded that other classes/methods are not necessary for interactive applications taking advantage of the REPL API. Tested via the following: $ export MAVEN_OPTS="-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m" $ mvn -Phadoop-2.3 -DskipTests clean package && mvn -Phadoop-2.3 test Also did a quick verification that I could start the shell and execute some code: $ ./bin/spark-shell ... scala> val x = 3 x: Int = 3 scala> sc.parallelize(1 to 10).reduce(_+_) ... res1: Int = 55 Author: Chip Senkbeil <[email protected]> Author: Chip Senkbeil <[email protected]> Closes #4034 from rcsenkbeil/AddDeveloperApiToRepl and squashes the following commits: 053ca75 [Chip Senkbeil] Fixed failed build by adding missing DeveloperApi import c1b88aa [Chip Senkbeil] Added DeveloperApi to public classes in repl 6dc1ee2 [Chip Senkbeil] Added missing method to expose error reporting flag 26fd286 [Chip Senkbeil] Refactored other Scala 2.10 classes and methods to be private/package protected where possible 925c112 [Chip Senkbeil] Added DeveloperApi and Scaladocs to SparkIMain for Scala 2.10
1 parent ecf943d commit d05c9ee

File tree

11 files changed

+644
-195
lines changed

11 files changed

+644
-195
lines changed

repl/scala-2.10/src/main/scala/org/apache/spark/repl/SparkCommandLine.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ package org.apache.spark.repl
1919

2020
import scala.tools.nsc.{Settings, CompilerCommand}
2121
import scala.Predef._
22+
import org.apache.spark.annotation.DeveloperApi
2223

2324
/**
2425
* Command class enabling Spark-specific command line options (provided by
2526
* <i>org.apache.spark.repl.SparkRunnerSettings</i>).
27+
*
28+
* @example new SparkCommandLine(Nil).settings
29+
*
30+
* @param args The list of command line arguments
31+
* @param settings The underlying settings to associate with this set of
32+
* command-line options
2633
*/
34+
@DeveloperApi
2735
class SparkCommandLine(args: List[String], override val settings: Settings)
2836
extends CompilerCommand(args, settings) {
29-
3037
def this(args: List[String], error: String => Unit) {
3138
this(args, new SparkRunnerSettings(error))
3239
}

repl/scala-2.10/src/main/scala/org/apache/spark/repl/SparkExprTyper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import scala.tools.nsc.ast.parser.Tokens.EOF
1515

1616
import org.apache.spark.Logging
1717

18-
trait SparkExprTyper extends Logging {
18+
private[repl] trait SparkExprTyper extends Logging {
1919
val repl: SparkIMain
2020

2121
import repl._

repl/scala-2.10/src/main/scala/org/apache/spark/repl/SparkHelper.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@
1717

1818
package scala.tools.nsc
1919

20+
import org.apache.spark.annotation.DeveloperApi
21+
22+
// NOTE: Forced to be public (and in scala.tools.nsc package) to access the
23+
// settings "explicitParentLoader" method
24+
25+
/**
26+
* Provides exposure for the explicitParentLoader method on settings instances.
27+
*/
28+
@DeveloperApi
2029
object SparkHelper {
30+
/**
31+
* Retrieves the explicit parent loader for the provided settings.
32+
*
33+
* @param settings The settings whose explicit parent loader to retrieve
34+
*
35+
* @return The Optional classloader representing the explicit parent loader
36+
*/
37+
@DeveloperApi
2138
def explicitParentLoader(settings: Settings) = settings.explicitParentLoader
2239
}

0 commit comments

Comments
 (0)