火花中的Encoders.product [scala特性] .schema [英] Encoders.product[of a scala trait ].schema in spark
本文介绍了火花中的Encoders.product [scala特性] .schema的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从特征创建火花模式?
考虑到特征:
How to create a schema for spark from a trait? Considering a trait:
trait A{
val name:String
val size:String
}
As:
Encoders.product[A].schema
给出:
Error:type arguments do not conform to method product's type parameter bounds [T <: Product]
字段数将大于案例类参数的限制> 200
Also the number of fields will be more then the limit of case class parameters > 200
推荐答案
案例类支持超过22列,请尝试在所有其他类/对象之外创建。如果您需要创建一个具有大量字段的数据框架构,则应该可以使用。
Case class do supports more than 22 columns, try creating outside all other class/object. If your need is to create a dataframe schema with large number of fields, this should work.
val schema: StructType = StructType(
Array(
StructField(name = "name", StringType),
StructField(name = "size", StringType)
)
)
val data = Seq(Row("Ramanan","29"))
spark.createDataFrame(spark.sparkContext.parallelize(data),schema).show()
这篇关于火花中的Encoders.product [scala特性] .schema的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文