简体   繁体   English

Spark将列表转换为数据框错误:不支持任何类型的架构

[英]Spark convert list to dataframe error: Schema for type Any is not supported

I ma trying to make create dataframe by doing the following: 我试图通过执行以下操作来创建数据框:

val df = Seq(
    ("tom", 25),
    ("andy", null)
).toDF("user", "rating")

but I get an error of "Schema for type Any is not supported". 但出现错误“不支持任何类型的架构”。 I think the rating column is causing the problem. 我认为评分栏引起了问题。

I want the rating column to be 我希望评分栏为

integer (nullable=true)

but i am not sure how to achieve that 但我不确定如何实现

You can use Option : 您可以使用Option

Seq(
  ("tom", Some(25)),
  ("andy", None)
).toDF("user", "rating")

You could also be more specific about the types and use java.lang.Integer : 您也可以更详细地说明类型,并使用java.lang.Integer

Seq[(String, java.lang.Integer)](
  ("tom", 25),
  ("andy", null)
).toDF("user", "rating")

but the first method should be preferred. 但是第一种方法应该是首选。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM