【发布时间】:2018-07-01 20:37:45
【问题描述】:
我正在尝试为我的新 DataFrame 创建一个架构,并尝试了各种括号和关键字的组合,但无法弄清楚如何使其工作。我目前的尝试:
from pyspark.sql.types import *
schema = StructType([
StructField("User", IntegerType()),
ArrayType(StructType([
StructField("user", StringType()),
StructField("product", StringType()),
StructField("rating", DoubleType())]))
])
返回错误:
elementType should be DataType
Traceback (most recent call last):
File "/usr/hdp/current/spark2-client/python/pyspark/sql/types.py", line 290, in __init__
assert isinstance(elementType, DataType), "elementType should be DataType"
AssertionError: elementType should be DataType
我用谷歌搜索过,但到目前为止还没有很好的对象数组示例。
【问题讨论】:
标签: pyspark schema spark-dataframe rdd