我正在尝试创建这样的架构:
root
|-- _ehid: string (nullable = true)
|-- duration: double (nullable = true)
|-- list: array (nullable = true)
| |-- element: array (containsNull = true)
| | |-- element: string (containsNull = true)
|-- request.id: string (nullable = true)
但我只能创建那个:
root
|-- _ehid: string (nullable = true)
|-- duration: double (nullable = true)
|-- list: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- element: string (nullable = true)
|-- request.id: string (nullable = true)
我看到元素的结构类型而不是数组。当我尝试通过 df.show(10) 查看我的 df 时,我只看到空值。
我的脚本:
schema = StructType([
StructField("_ehid", StringType(), True),
StructField("duration", DoubleType(), True),
StructField("list", ArrayType(StructType([
StructField("element", StringType())
])), True),
StructField("request.id", StringType(), True)])
最佳答案
直接使用StringType
即可:
schema = StructType([
StructField("_ehid", StringType(), True),
StructField("duration", DoubleType(), True),
StructField("list", ArrayType(ArrayType(StringType())), True),
StructField("request.id", StringType(), True)])
关于python - 皮斯帕克。如何创建像这样的 df.shema ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53959188/