【问题标题】:Overloaded method value apply with alternatives:重载的方法值适用于替代方案:
【发布时间】:2017-12-20 19:05:52
【问题描述】:

我是 spark 新手,我试图为 json 数据定义架构,但在 (spark-shell,

<console>:28: error: overloaded method value apply with alternatives:
  (fields: Array[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType <and>
  (fields: java.util.List[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType <and>
  (fields: Seq[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType
 cannot be applied to (org.apache.spark.sql.types.StructField, org.apache.spark.sql.types.StructField)
       val schema = StructType(Array(StructField("type", StructType(StructField("name", StringType,   true), StructField("version", StringType,   true)), true) :: StructField("value", StructType(StructField("answerBlacklistedEntities", StringType,   true) :: StructField("answerBlacklistedPhrase", StringType,   true) :: StructField("answerEntities", StringType,   true) :: StructField("answerText", StringType,   true) :: StructField("blacklistReason", StringType,   true) :: StructField("blacklistedDomains", StringType,   true) :: StructField("blacklistedEntities", ArrayType(StringType, true), true) :: StructField("customerId", StringType,   true) :: StructField("impolitePhrase", StringType,   true) :: StructField("isResponseBlacklisted", BooleanType,   true) :: StructField("queryString", StringType,   true) :: StructField("utteranceDomains", StringType,   true) :: StructField("utteranceEntities", ArrayType(StringType, true), true) :: StructField("utteranceId", StructType(StructField("identifier", StringType, true)), true)) :: Nil)))

谁能指导我这里发生了什么? :) 非常感谢您的帮助!

【问题讨论】:

    标签: scala apache-spark


    【解决方案1】:

    这是因为:

    val schema = StructType(Array(StructField("type", 
       StructType(StructField("name", StringType,   true), ...))
    

    您创建StructType 并将StructField 作为参数传递,而它应该是StructFields 的序列:

    val schema = StructType(Array(StructField("type", 
       StructType(Array(StructField("name", StringType,   true), ...)) ...)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-17
      • 1970-01-01
      • 2015-07-05
      • 2021-09-12
      相关资源
      最近更新 更多