【发布时间】:2016-08-25 17:17:11
【问题描述】:
我正在尝试导入 spark.implicits._ 显然,这是 scala 类中的一个对象。 当我以这样的方法导入它时:
def f() = {
val spark = SparkSession()....
import spark.implicits._
}
它工作正常,但是我正在编写一个测试类,我想让这个导入可用于所有测试 我试过了:
class SomeSpec extends FlatSpec with BeforeAndAfter {
var spark:SparkSession = _
//This won't compile
import spark.implicits._
before {
spark = SparkSession()....
//This won't either
import spark.implicits._
}
"a test" should "run" in {
//Even this won't compile (although it already looks bad here)
import spark.implicits._
//This was the only way i could make it work
val spark = this.spark
import spark.implicits._
}
}
这不仅看起来很糟糕,我不想每次测试都这样做 什么是“正确”的做法?
【问题讨论】:
-
为什么不在文件顶部?通常所有的进口都在那里
-
也试过了,忘了写代码,但显然不可能,因为“implicits”是“spark”类中的一个对象,需要先实例化
标签: scala apache-spark