मैं spark.implicits._ आयात करने की कोशिश कर रहा हूं जाहिर है, यह स्केल में कक्षा के अंदर एक वस्तु है। जब मैं तो जैसे एक विधि में आयात:scala में spark.implicits._ आयात करना
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._
}
}
न केवल यह बुरा दिखता है, मैं इसे प्रत्येक टेस्ट के लिए नहीं करना चाहता हूं इसे करने का "सही" तरीका क्या है?
फ़ाइल के शीर्ष पर क्यों नहीं? आम तौर पर सभी आयात – spiffman
कोशिश करते हैं कि कोड में लिखना भूल गए, लेकिन स्पष्ट रूप से यह संभव नहीं है क्योंकि "implicits" "स्पार्क" वर्ग के अंदर एक वस्तु है और इसे पहले तत्काल करने की आवश्यकता है – ShinySpiderdude