I have the following class, the run
returns a list of ints from a database table.
class ItemList(sqlContext: org.apache.spark.sql.SQLContext, jdbcSqlConn: String) {
def run(date: LocalDate) = {
sqlContext.read.format("jdbc").options(Map(
"driver" -> "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"url" -> jdbcSqlConn,
"dbtable" -> s"dbo.GetList('$date')"
)).load()
}
}
The following code
val conf = new SparkConf()
val sc = new SparkContext(conf.setAppName("Test").setMaster("local[*]"))
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val itemListJob = new ItemList(sqlContext, jdbcSqlConn)
val processed = itemListJob.run(rc, priority).select("id").map(d => {
runJob.run(d) // d expected to be int
})
processed.saveAsTextFile("c:\\temp\\mpa")
get the error of
[error] ...\src\main\scala\main.scala:39: type mismatch; [error] found : org.apache.spark.sql.Row [error] required: Int [error] runJob.run(d) [error] ^ [error] one error found [error] (compile:compileIncremental) Compilation failed
I tried
val processed = itemListJob.run(rc, priority).select("id").as[Int].map(d =>
case class itemListRow(id: Int); ....as[itemListRow].
Both of them got errors of
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.
Update: I'm trying to add the import implicits statements
import sc.implicits._
got error ofvalue implicits is not a member of org.apache.spark.SparkContext
import sqlContext.implicits._
is OK. However, the later statement ofprocessed.saveAsTextFile("c:\\temp\\mpa")
got the error ofvalue saveAsTextFile is not a member of org.apache.spark.sql.Dataset[(Int, java.time.LocalDate)]