Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion repl/src/main/scala/org/apache/spark/repl/SparkJLineReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

package org.apache.spark.repl

import scala.reflect.io.{Path, File}
import scala.tools.nsc._
import scala.tools.nsc.interpreter._
import scala.tools.nsc.interpreter.session.JLineHistory.JLineFileHistory

import scala.tools.jline.console.ConsoleReader
import scala.tools.jline.console.completer._
Expand All @@ -25,7 +27,7 @@ class SparkJLineReader(_completion: => Completion) extends InteractiveReader {
val consoleReader = new JLineConsoleReader()

lazy val completion = _completion
lazy val history: JLineHistory = JLineHistory()
lazy val history: JLineHistory = new SparkJLineHistory

private def term = consoleReader.getTerminal()
def reset() = term.reset()
Expand Down Expand Up @@ -78,3 +80,11 @@ class SparkJLineReader(_completion: => Completion) extends InteractiveReader {
def readOneLine(prompt: String) = consoleReader readLine prompt
def readOneKey(prompt: String) = consoleReader readOneKey prompt
}

/** Changes the default history file to not collide with the scala repl's. */
class SparkJLineHistory extends JLineFileHistory {
import Properties.userHome

def defaultFileName = ".spark_history"
override protected lazy val historyFile = File(Path(userHome) / defaultFileName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering - does this handle systems with different path separators correctly?

Does historyFile need to be scala.reflect.io.File? Or can it be a java.io.File? It seems a little heavyweight to pull in the reflection library to create a file path, but it makes sense if this is the needed type of historyFile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I did this was to fully mimic the code from the Scala interpreter. I think this will make it easier to compare in case the Scala version is updated some time in the future, but you're right we could use a lighter weight construct, we just risk having different behavior than the standard Scala shell history.

Not a big deal to me, but I'm inclined to stick with cloning the Scala shell behavior. Let me know if you still prefer the java.io.File route, I'd be happy to change to that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sounds good - just wondering why it was there.

}