How to tell whether i am running under Ammonite repl or in a script?

66 Views Asked by At

I was trying to use different builders to build the SparkSession and AmmoniteSparkSession requires repl.

This won't work, i think it is because repl is a compile time error.

val sparkSessionBuilder =
  try {
    repl
    AmmoniteSparkSession.builder
  } catch {
    case e: Exception => SparkSession.builder
  }
1

There are 1 best solutions below

0
Dyno Fu On

as it is compile time, we have to use the Multi-stageScripts to load different script according to the context. it should work something like here

val sparkSessionModule = sys.env.get("AMMONITE_REPL") match {
  case None => pwd / RelPath("libs/_SparkSession.sc")
  case Some(_) => pwd / RelPath("libs/_AmmoniteSparkSession.sc")
}
interp.load.module(sparkSessionModule)
@