[英]Error while performing aggregate functions in Spark: ArrayType cannot be cast to org.apache.spark.sql.types.StructType
[英]Schema for type org.apache.spark.sql.types.DataType is not supported
我尝试使用架构创建空 df:
val sparkConf = new SparkConf()
.setAppName("app")
.setMaster("local")
val sparkSession = SparkSession
.builder()
.config(sparkConf)
.getOrCreate()
val sparkContext = sparkSession.sparkContext
var tmpScheme = StructType(
StructField("source_id", StringType, true) :: Nil)
var df = conf.SparkConf.sparkSession.createDataFrame(tmpScheme)
并得到Schema for type org.apache.spark.sql.types.DataType is not supported...
我不明白为什么 - 即使在 Imports 中也没有.DataType
:
import org.apache.spark.sql.types.{BooleanType, IntegerType, StringType, StructField, StructType}
这可能是什么问题?
PS:火花版
"org.apache.spark" %% "spark-sql" % "3.2.2", // spark
"org.apache.spark" %% "spark-core" % "3.2.2", // spark
如果您查看文档,您可以看到StructType
的参数fields
是Array[StructField]
类型并且您正在传递StructField
。
这意味着您应该用Array
包装您的StructField
,例如:
val simpleSchema = StructType(Array(
StructField("source_id", StringType, true))
)
祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.