[英]Schema for type Any is not supported
I'm trying to create a spark UDF to extract a Map of (key, value) pairs from a User defined case class.我正在尝试创建一个 spark UDF 来从用户定义的案例类中提取(键,值)对的映射。
The scala function seems to work fine, but when I try to convert that to a UDF in spark2.0, I'm running into the " Schema for type Any is not supported" error. scala 函数似乎工作正常,但是当我尝试在 spark2.0 中将其转换为 UDF 时,我遇到了“不支持任何类型的架构”错误。
case class myType(c1: String, c2: Int)
def getCaseClassParams(cc: Product): Map[String, Any] = {
cc
.getClass
.getDeclaredFields // all field names
.map(_.getName)
.zip(cc.productIterator.to) // zipped with all values
.toMap
}
But when I try to instantiate a function value as a UDF it results in the following error -但是当我尝试将函数值实例化为 UDF 时,它会导致以下错误 -
val ccUDF = udf{(cc: Product, i: String) => getCaseClassParams(cc).get(i)}
java.lang.UnsupportedOperationException: Schema for type Any is not supported
at org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:716)
at org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:668)
at org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:654)
at org.apache.spark.sql.functions$.udf(functions.scala:2841)
The error message says it all.错误消息说明了一切。 You have an Any in the map.您在地图中有一个 Any 。 Spark SQL and Dataset api does not support Any in the schema. Spark SQL 和 Dataset api 不支持架构中的 Any。 It has to be one of the supported type (which is a list of basic types such as String, Integer etc. a sequence of supported types or a map of supported types).它必须是受支持的类型之一(它是基本类型的列表,例如字符串、整数等。支持类型的序列或支持类型的映射)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.