java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
at org.apache.spark.sql.Row$class.getString(Row.scala:255)
at org.apache.spark.sql.catalyst.expressions.GenericRow.getString(rows.scala:166)
查看spark源码
def getString(i: Int): String = getAs[String](i)
def getAs[T](i: Int): T = get(i).asInstanceOf[T]
spark row对象的getString方法是通过asInstanceOf来转换数据类型的,而double类型是通过asInstanceOf来转成string 会因为泛型擦除问题而报错,可以将getString方法用get代替
java最大允许255个参数,long、doubule,会占用两个单位数,所以scala的样例类要减少参数数量。