我尝试在 Spark 中分解复杂数据帧的结构。我只对根目录下的嵌套数组感兴趣。问题是我无法从 StructField 类型中检索 ElementType。
这是一个示例,这是 StructType Object 的架构:
df.printSchema
result>>
root
|-- ID: string (nullable = true)
|-- creationDate: string (nullable = true)
|-- personsList: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- firstName: string (nullable = true)
| | |-- lastName: string (nullable = true)
每个 StructType 都是一个数组
FieldType ( name, type, nullable , metadata).
我尝试了下面的代码:
val personsList = df.schema("personsList") // personsList is a StructField
println(passengersList.dataType)
我想检索 ElementType 以获得嵌套数组的 StructType,但不幸的是我们只有 typeName 或 json 方法。
此致,