先上报错
Caused by: java.lang.NullPointerException: Null value appeared in non-nullable field:
- field (class: "scala.Long", name: "f_cell_id")
- root class: "com.xwsoft.structure.Bts"
If the schema is inferred from a Scala tuple/case class, or a Java bean, please try to use scala.Option[_] or other nullable types (e.g. java.lang.Integer instead of int/scala.Int).
样例类及处理逻辑如下
case class Bts(f_cell_id: Long, f_latitude: Double, f_longitude: Double)
//处理逻辑
spark.read.jdbc(appConfig.mysqlJDBCURL, appConfig.btsTable, jdbcProperties)
.createOrReplaceTempView("bj_cfg_bts")
val btsSet: Set[Bts] = spark.sql(
"""
|select
|cast(f_cell_id as long) as f_cell_id,
|cast(f_longitude as double) as f_longitude,
|cast(f_latitude as double) as f_latitude
|from bj_cfg_bts
|""".stripMargin)