![](/img/trans.png)
[英]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.