Python Pypark can';t将DICT的RDD转换为数据帧。错误:无法接受类型中的对象<;类别';pyspark.sql.types.Row'&燃气轮机;

Python Pypark can';t将DICT的RDD转换为数据帧。错误:无法接受类型中的对象<;类别';pyspark.sql.types.Row'&燃气轮机;,python,apache-spark,pyspark,apache-spark-sql,Python,Apache Spark,Pyspark,Apache Spark Sql,我目前正在使用Spark 1.4.1,无法将带有嵌套dict的dict转换为Spark数据帧。我将嵌套的dict转换为行,但它似乎不接受我的模式 以下是重现我的错误的代码: 从pyspark.sql导入行,SQLContext,类型为pst sqlContext=sqlContext(sc) 示例_dict=Row(**{“name”:“Mike”,“data”:Row(**{“age”:10,“like”:True}) 示例rdd=sc.parallelize([示例dict]) 嵌套的_字段

我目前正在使用Spark 1.4.1,无法将带有嵌套dict的dict转换为Spark
数据帧。我将嵌套的
dict
转换为
,但它似乎不接受我的模式

以下是重现我的错误的代码:

从pyspark.sql导入行,SQLContext,类型为pst
sqlContext=sqlContext(sc)
示例_dict=Row(**{“name”:“Mike”,“data”:Row(**{“age”:10,“like”:True})
示例rdd=sc.parallelize([示例dict])
嵌套的_字段=[pst.StructField(“age”,pst.IntegerType(),True),
pst.StructField(“like”,pst.BooleanType(),True)]
schema=pst.StructType([
pst.StructField(“数据”,pst.StructType(嵌套的_字段),True),
pst.StructField(“名称”,pst.StringType(),True)
])
df=sqlContext.createDataFrame(示例rdd,模式)
TypeError:StructType(列表(StructField(age,IntegerType,true),StructField(like,BooleanType,true))不能接受类型中的对象
我不知道为什么我会收到这个错误。以下是对象
rdd
schema

>>> example_rdd.first()
Row(data=Row(age=10, like=True), name='Mike')

>>> schema
StructType(List(StructField(data,StructType(List(StructField(age,IntegerType,true),StructField(like,BooleanType,true))),true),StructField(name,StringType,true)))
我不确定是否遗漏了什么,但架构似乎与对象匹配。Spark 1.4.1是否有理由不接受行内的行


请注意:这不是
Spark 2.0.2
中的问题,但不幸的是,我使用的是
Spark 1.4.1
共享资源,因此我需要暂时找到解决方法:(.任何帮助都将不胜感激,提前感谢!

发生这种情况是因为Spark 1.4中不接受
作为
结构类型
。接受的类型有:

pst._acceptable_types[pst.StructType]
(元组,列表)
Spark做了一个简单的检查:

type(obj) not in _acceptable_types[_type]
这显然不适用于
对象。与当前版本中发生的情况相同的正确条件是:

isinstance(obj, _acceptable_types[_type])
如果要使用嵌套列,可以使用纯Python
tuple

Row(**{"name": "Mike", "data": (10, True)})

((10, True), "Mike")