Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/21749#discussion_r201793790
--- Diff:
repl/scala-2.11/src/main/scala/org/apache/spark/repl/SparkILoop.scala ---
@@ -116,6 +124,132 @@ class SparkILoop(in0: Option[BufferedReader], out:
JPrintWriter)
super.replay()
}
+ /**
+ * The following code is mostly a copy of `process` implementation in
`ILoop.scala` in Scala
+ *
+ * In newer version of Scala, `printWelcome` is the first thing to be
called. As a result,
+ * SparkUI URL information would be always shown after the welcome
message.
+ *
+ * However, this is inconsistent compared with the existing version of
Spark which will always
+ * show SparkUI URL first.
+ *
+ * The only way we can make it consistent will be duplicating the Scala
code.
+ *
+ * We should remove this duplication once Scala provides a way to load
our custom initialization
+ * code, and also customize the ordering of printing welcome message.
+ */
+ override def process(settings: Settings): Boolean = savingContextLoader {
+
+ def newReader = in0.fold(chooseReader(settings))(r => SimpleReader(r,
out, interactive = true))
+
+ /** Reader to use before interpreter is online. */
+ def preLoop = {
+ val sr = SplashReader(newReader) { r =>
+ in = r
+ in.postInit()
+ }
+ in = sr
+ SplashLoop(sr, prompt)
+ }
+
+ /* Actions to cram in parallel while collecting first user input at
prompt.
+ * Run with output muted both from ILoop and from the intp reporter.
+ */
+ def loopPostInit(): Unit = mumly {
+ // Bind intp somewhere out of the regular namespace where
+ // we can get at it in generated code.
+ intp.quietBind(NamedParam[IMain]("$intp", intp)(tagOfIMain,
classTag[IMain]))
+
+ // Auto-run code via some setting.
+ ( replProps.replAutorunCode.option
+ flatMap (f => File(f).safeSlurp())
+ foreach (intp quietRun _)
+ )
+ // power mode setup
+ if (isReplPower) enablePowerMode(true)
+ initializeSpark()
+ loadInitFiles()
+ // SI-7418 Now, and only now, can we enable TAB completion.
+ in.postInit()
+ }
+ def loadInitFiles(): Unit = settings match {
+ case settings: GenericRunnerSettings =>
+ for (f <- settings.loadfiles.value) {
+ loadCommand(f)
+ addReplay(s":load $f")
+ }
+ for (f <- settings.pastefiles.value) {
+ pasteCommand(f)
+ addReplay(s":paste $f")
+ }
+ case _ =>
+ }
+ // wait until after startup to enable noisy settings
+ def withSuppressedSettings[A](body: => A): A = {
+ val ss = this.settings
+ import ss._
+ val noisy = List(Xprint, Ytyperdebug)
+ val noisesome = noisy.exists(!_.isDefault)
+ val current = (Xprint.value, Ytyperdebug.value)
+ if (isReplDebug || !noisesome) body
+ else {
+ this.settings.Xprint.value = List.empty
+ this.settings.Ytyperdebug.value = false
+ try body
+ finally {
+ Xprint.value = current._1
+ Ytyperdebug.value = current._2
+ intp.global.printTypings = current._2
+ }
+ }
+ }
+ def startup(): String = withSuppressedSettings {
+ // let them start typing
+ val splash = preLoop
+
+ // while we go fire up the REPL
+ try {
+ // don't allow ancient sbt to hijack the reader
+ savingReader {
+ createInterpreter()
+ }
+ intp.initializeSynchronous()
+
+ val field =
classOf[ILoop].getDeclaredFields.filter(_.getName.contains("globalFuture")).head
+ field.setAccessible(true)
+ field.set(this, Future successful true)
--- End diff --
This reflection has to be used to access private `globalFuture` in `ILoop`.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]