简体   繁体   English

如何判断我是在 Ammonite repl 下运行还是在脚本中运行?

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

I was trying to use different builders to build the SparkSession and AmmoniteSparkSession requires repl.我试图使用不同的构建器来构建 SparkSession,而AmmoniteSparkSession需要 repl。

This won't work, i think it is because repl is a compile time error.这行不通,我认为这是因为 repl 是编译时错误。

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

as it is compile time, we have to use the Multi-stageScripts to load different script according to the context.由于是编译时,我们必须使用Multi-stageScripts根据上下文加载不同的脚本。 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)
@

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM