6
Spala 세션을 초기화하고 파괴하는 상용구 코드를 피하기 위해 ScalaTest FunSuite 테스트를 리팩토링하려고합니다.SpalaTest FunSuite를 구현하여 상용구를 피하는 방법 Spark 코드 및 가져 오기 implicits
문제는 내가 암시 적 함수를 가져올 필요가 있지만 이전/이후 접근 변수 (var 필드) 만 사용할 수 있으며 가져 오기는 필수적인 값 (val 필드)입니다.
아이디어는 모든 테스트 실행시 새로운 깨끗한 스파크 세션을 갖는 것입니다.
을는 SqlContext 확인할 수 없습니다이 기호는이 문제를 해결하는 방법
import org.apache.spark.SparkContext
import org.apache.spark.sql.{SQLContext, SparkSession}
import org.scalatest.{BeforeAndAfter, FunSuite}
object SimpleWithBeforeTest extends FunSuite with BeforeAndAfter {
var spark: SparkSession = _
var sc: SparkContext = _
implicit var sqlContext: SQLContext = _
before {
spark = SparkSession.builder
.master("local")
.appName("Spark session for testing")
.getOrCreate()
sc = spark.sparkContext
sqlContext = spark.sqlContext
}
after {
spark.sparkContext.stop()
}
test("Import implicits inside the test 1") {
import sqlContext.implicits._
// Here other stuff
}
test("Import implicits inside the test 2") {
import sqlContext.implicits._
// Here other stuff
}
그러나 라인 import sqlContext.implicits._
에서 나는 오류가 있습니다
내가 이런 일을하려고 또는 테스트 클래스를 구현하는 방법?