簡體   English   中英

不支持類型 org.apache.spark.sql.types.DataType 的模式

[英]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的參數fieldsArray[StructField]類型並且您正在傳遞StructField

這意味着您應該用Array包裝您的StructField ,例如:

val simpleSchema = StructType(Array(
  StructField("source_id", StringType, true))
)

祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM