Skip to content

Commit c7967c6

Browse files
dbtsaijerryshao
authored andcommitted
[SPARK-24418][BUILD] Upgrade Scala to 2.11.12 and 2.12.6
## What changes were proposed in this pull request? Scala is upgraded to `2.11.12` and `2.12.6`. We used `loadFIles()` in `ILoop` as a hook to initialize the Spark before REPL sees any files in Scala `2.11.8`. However, it was a hack, and it was not intended to be a public API, so it was removed in Scala `2.11.12`. From the discussion in Scala community, scala/bug#10913 , we can use `initializeSynchronous` to initialize Spark instead. This PR implements the Spark initialization there. However, in Scala `2.11.12`'s `ILoop.scala`, in function `def startup()`, the first thing it calls is `printWelcome()`. As a result, Scala will call `printWelcome()` and `splash` before calling `initializeSynchronous`. Thus, the Spark shell will allow users to type commends first, and then show the Spark UI URL. It's working, but it will change the Spark Shell interface as the following. ```scala ➜ apache-spark git:(scala-2.11.12) ✗ ./bin/spark-shell Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 2.4.0-SNAPSHOT /_/ Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_161) Type in expressions to have them evaluated. Type :help for more information. scala> Spark context Web UI available at http://192.168.1.169:4040 Spark context available as 'sc' (master = local[*], app id = local-1528180279528). Spark session available as 'spark'. scala> ``` It seems there is no easy way to inject the Spark initialization code in the proper place as Scala doesn't provide a hook. Maybe som-snytt can comment on this. The following command is used to update the dep files. ```scala ./dev/test-dependencies.sh --replace-manifest ``` ## How was this patch tested? Existing tests Author: DB Tsai <[email protected]> Closes #21495 from dbtsai/scala-2.11.12.
1 parent 4c059eb commit c7967c6

File tree

7 files changed

+50
-42
lines changed

7 files changed

+50
-42
lines changed

LICENSE

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,18 +243,18 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
243243
(BSD licence) ANTLR ST4 4.0.4 (org.antlr:ST4:4.0.4 - http://www.stringtemplate.org)
244244
(BSD licence) ANTLR StringTemplate (org.antlr:stringtemplate:3.2.1 - http://www.stringtemplate.org)
245245
(BSD License) Javolution (javolution:javolution:5.5.1 - http://javolution.org)
246-
(BSD) JLine (jline:jline:0.9.94 - http://jline.sourceforge.net)
246+
(BSD) JLine (jline:jline:2.14.3 - https://github.com/jline/jline2)
247247
(BSD) ParaNamer Core (com.thoughtworks.paranamer:paranamer:2.3 - http://paranamer.codehaus.org/paranamer)
248248
(BSD) ParaNamer Core (com.thoughtworks.paranamer:paranamer:2.6 - http://paranamer.codehaus.org/paranamer)
249249
(BSD 3 Clause) Scala (http://www.scala-lang.org/download/#License)
250250
(Interpreter classes (all .scala files in repl/src/main/scala
251251
except for Main.Scala, SparkHelper.scala and ExecutorClassLoader.scala),
252252
and for SerializableMapWrapper in JavaUtils.scala)
253-
(BSD-like) Scala Actors library (org.scala-lang:scala-actors:2.11.8 - http://www.scala-lang.org/)
254-
(BSD-like) Scala Compiler (org.scala-lang:scala-compiler:2.11.8 - http://www.scala-lang.org/)
255-
(BSD-like) Scala Compiler (org.scala-lang:scala-reflect:2.11.8 - http://www.scala-lang.org/)
256-
(BSD-like) Scala Library (org.scala-lang:scala-library:2.11.8 - http://www.scala-lang.org/)
257-
(BSD-like) Scalap (org.scala-lang:scalap:2.11.8 - http://www.scala-lang.org/)
253+
(BSD-like) Scala Actors library (org.scala-lang:scala-actors:2.11.12 - http://www.scala-lang.org/)
254+
(BSD-like) Scala Compiler (org.scala-lang:scala-compiler:2.11.12 - http://www.scala-lang.org/)
255+
(BSD-like) Scala Compiler (org.scala-lang:scala-reflect:2.11.12 - http://www.scala-lang.org/)
256+
(BSD-like) Scala Library (org.scala-lang:scala-library:2.11.12 - http://www.scala-lang.org/)
257+
(BSD-like) Scalap (org.scala-lang:scalap:2.11.12 - http://www.scala-lang.org/)
258258
(BSD-style) scalacheck (org.scalacheck:scalacheck_2.11:1.10.0 - http://www.scalacheck.org)
259259
(BSD-style) spire (org.spire-math:spire_2.11:0.7.1 - http://spire-math.org)
260260
(BSD-style) spire-macros (org.spire-math:spire-macros_2.11:0.7.1 - http://spire-math.org)

dev/deps/spark-deps-hadoop-2.6

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jersey-server-2.22.2.jar
122122
jets3t-0.9.4.jar
123123
jetty-6.1.26.jar
124124
jetty-util-6.1.26.jar
125-
jline-2.12.1.jar
125+
jline-2.14.3.jar
126126
joda-time-2.9.3.jar
127127
jodd-core-3.5.2.jar
128128
jpam-1.1.jar
@@ -172,10 +172,10 @@ parquet-jackson-1.10.0.jar
172172
protobuf-java-2.5.0.jar
173173
py4j-0.10.7.jar
174174
pyrolite-4.13.jar
175-
scala-compiler-2.11.8.jar
176-
scala-library-2.11.8.jar
177-
scala-parser-combinators_2.11-1.0.4.jar
178-
scala-reflect-2.11.8.jar
175+
scala-compiler-2.11.12.jar
176+
scala-library-2.11.12.jar
177+
scala-parser-combinators_2.11-1.1.0.jar
178+
scala-reflect-2.11.12.jar
179179
scala-xml_2.11-1.0.5.jar
180180
shapeless_2.11-2.3.2.jar
181181
slf4j-api-1.7.16.jar

dev/deps/spark-deps-hadoop-2.7

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jersey-server-2.22.2.jar
122122
jets3t-0.9.4.jar
123123
jetty-6.1.26.jar
124124
jetty-util-6.1.26.jar
125-
jline-2.12.1.jar
125+
jline-2.14.3.jar
126126
joda-time-2.9.3.jar
127127
jodd-core-3.5.2.jar
128128
jpam-1.1.jar
@@ -173,10 +173,10 @@ parquet-jackson-1.10.0.jar
173173
protobuf-java-2.5.0.jar
174174
py4j-0.10.7.jar
175175
pyrolite-4.13.jar
176-
scala-compiler-2.11.8.jar
177-
scala-library-2.11.8.jar
178-
scala-parser-combinators_2.11-1.0.4.jar
179-
scala-reflect-2.11.8.jar
176+
scala-compiler-2.11.12.jar
177+
scala-library-2.11.12.jar
178+
scala-parser-combinators_2.11-1.1.0.jar
179+
scala-reflect-2.11.12.jar
180180
scala-xml_2.11-1.0.5.jar
181181
shapeless_2.11-2.3.2.jar
182182
slf4j-api-1.7.16.jar

dev/deps/spark-deps-hadoop-3.1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jersey-server-2.22.2.jar
122122
jets3t-0.9.4.jar
123123
jetty-webapp-9.3.20.v20170531.jar
124124
jetty-xml-9.3.20.v20170531.jar
125-
jline-2.12.1.jar
125+
jline-2.14.3.jar
126126
joda-time-2.9.3.jar
127127
jodd-core-3.5.2.jar
128128
jpam-1.1.jar
@@ -192,10 +192,10 @@ protobuf-java-2.5.0.jar
192192
py4j-0.10.7.jar
193193
pyrolite-4.13.jar
194194
re2j-1.1.jar
195-
scala-compiler-2.11.8.jar
196-
scala-library-2.11.8.jar
197-
scala-parser-combinators_2.11-1.0.4.jar
198-
scala-reflect-2.11.8.jar
195+
scala-compiler-2.11.12.jar
196+
scala-library-2.11.12.jar
197+
scala-parser-combinators_2.11-1.1.0.jar
198+
scala-reflect-2.11.12.jar
199199
scala-xml_2.11-1.0.5.jar
200200
shapeless_2.11-2.3.2.jar
201201
slf4j-api-1.7.16.jar

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<commons.math3.version>3.4.1</commons.math3.version>
156156
<!-- managed up from 3.2.1 for SPARK-11652 -->
157157
<commons.collections.version>3.2.2</commons.collections.version>
158-
<scala.version>2.11.8</scala.version>
158+
<scala.version>2.11.12</scala.version>
159159
<scala.binary.version>2.11</scala.binary.version>
160160
<codehaus.jackson.version>1.9.13</codehaus.jackson.version>
161161
<fasterxml.jackson.version>2.6.7</fasterxml.jackson.version>
@@ -740,13 +740,13 @@
740740
<dependency>
741741
<groupId>org.scala-lang.modules</groupId>
742742
<artifactId>scala-parser-combinators_${scala.binary.version}</artifactId>
743-
<version>1.0.4</version>
743+
<version>1.1.0</version>
744744
</dependency>
745745
<!-- SPARK-16770 affecting Scala 2.11.x -->
746746
<dependency>
747747
<groupId>jline</groupId>
748748
<artifactId>jline</artifactId>
749-
<version>2.12.1</version>
749+
<version>2.14.3</version>
750750
</dependency>
751751
<dependency>
752752
<groupId>org.scalatest</groupId>
@@ -2755,7 +2755,7 @@
27552755
<profile>
27562756
<id>scala-2.12</id>
27572757
<properties>
2758-
<scala.version>2.12.4</scala.version>
2758+
<scala.version>2.12.6</scala.version>
27592759
<scala.binary.version>2.12</scala.binary.version>
27602760
</properties>
27612761
<build>

repl/scala-2.11/src/main/scala/org/apache/spark/repl/SparkILoop.scala

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SparkILoop(in0: Option[BufferedReader], out: JPrintWriter)
3636
def this() = this(None, new JPrintWriter(Console.out, true))
3737

3838
override def createInterpreter(): Unit = {
39-
intp = new SparkILoopInterpreter(settings, out)
39+
intp = new SparkILoopInterpreter(settings, out, initializeSpark)
4040
}
4141

4242
val initializationCommands: Seq[String] = Seq(
@@ -73,11 +73,15 @@ class SparkILoop(in0: Option[BufferedReader], out: JPrintWriter)
7373
"import org.apache.spark.sql.functions._"
7474
)
7575

76-
def initializeSpark() {
77-
intp.beQuietDuring {
78-
savingReplayStack { // remove the commands from session history.
79-
initializationCommands.foreach(processLine)
76+
def initializeSpark(): Unit = {
77+
if (!intp.reporter.hasErrors) {
78+
// `savingReplayStack` removes the commands from session history.
79+
savingReplayStack {
80+
initializationCommands.foreach(intp quietRun _)
8081
}
82+
} else {
83+
throw new RuntimeException(s"Scala $versionString interpreter encountered " +
84+
"errors during initialization")
8185
}
8286
}
8387

@@ -101,16 +105,6 @@ class SparkILoop(in0: Option[BufferedReader], out: JPrintWriter)
101105
/** Available commands */
102106
override def commands: List[LoopCommand] = standardCommands
103107

104-
/**
105-
* We override `loadFiles` because we need to initialize Spark *before* the REPL
106-
* sees any files, so that the Spark context is visible in those files. This is a bit of a
107-
* hack, but there isn't another hook available to us at this point.
108-
*/
109-
override def loadFiles(settings: Settings): Unit = {
110-
initializeSpark()
111-
super.loadFiles(settings)
112-
}
113-
114108
override def resetCommand(line: String): Unit = {
115109
super.resetCommand(line)
116110
initializeSpark()

repl/scala-2.11/src/main/scala/org/apache/spark/repl/SparkILoopInterpreter.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@ import scala.collection.mutable
2121
import scala.tools.nsc.Settings
2222
import scala.tools.nsc.interpreter._
2323

24-
class SparkILoopInterpreter(settings: Settings, out: JPrintWriter) extends IMain(settings, out) {
25-
self =>
24+
class SparkILoopInterpreter(settings: Settings, out: JPrintWriter, initializeSpark: () => Unit)
25+
extends IMain(settings, out) { self =>
26+
27+
/**
28+
* We override `initializeSynchronous` to initialize Spark *after* `intp` is properly initialized
29+
* and *before* the REPL sees any files in the private `loadInitFiles` functions, so that
30+
* the Spark context is visible in those files.
31+
*
32+
* This is a bit of a hack, but there isn't another hook available to us at this point.
33+
*
34+
* See the discussion in Scala community https://github.com/scala/bug/issues/10913 for detail.
35+
*/
36+
override def initializeSynchronous(): Unit = {
37+
super.initializeSynchronous()
38+
initializeSpark()
39+
}
2640

2741
override lazy val memberHandlers = new {
2842
val intp: self.type = self

0 commit comments

Comments
 (0)