I'm new to Spark 2.0 and using datasets in our code base. I'm kinda noticing that I need to import spark.implicits._
everywhere in our code. For example:
File A
class A {
def job(spark: SparkSession) = {
import spark.implcits._
//create dataset ds
val b = new B(spark)
b.doSomething(ds)
doSomething(ds)
}
private def doSomething(ds: Dataset[Foo], spark: SparkSession) = {
import spark.implicits._
ds.map(e => 1)
}
}
File B
class B(spark: SparkSession) {
def doSomething(ds: Dataset[Foo]) = {
import spark.implicits._
ds.map(e => "SomeString")
}
}
What I wanted to ask is if there's a cleaner way to be able to do
ds.map(e => "SomeString")
without importing implicits in every function where I do the map? If I don't import it, I get the following error:
Error:(53, 13) Unable to find encoder for type stored in a Dataset. Primitive types (Int, String, etc) and Product types (case classes) are supported by importing spark.implicits._ Support for serializing other types will be added in future releases.