【发布时间】:2020-05-06 04:34:26
【问题描述】:
我希望收集嵌套模式中所有字段的名称。数据是从 json 文件导入的。
架构如下:
root
|-- column_a: string (nullable = true)
|-- column_b: string (nullable = true)
|-- column_c: struct (nullable = true)
| |-- nested_a: struct (nullable = true)
| | |-- double_nested_a: string (nullable = true)
| | |-- double_nested_b: string (nullable = true)
| | |-- double_nested_c: string (nullable = true)
| |-- nested_b: string (nullable = true)
|-- column_d: string (nullable = true)
如果我使用df.schema.fields 或df.schema.names,它只会打印列层的名称——没有嵌套列。
我想要的输出是一个python列表,其中包含所有列名,例如:
['column_a', 'columb_b', 'column_c.nested_a.double_nested.a', 'column_c.nested_a.double_nested.b', etc...]
如果我想编写自定义函数,信息就在那里 - 但我错过了一个节拍吗?有没有一种方法可以满足我的需要?
【问题讨论】:
标签: apache-spark pyspark apache-spark-sql