【发布时间】:2022-01-24 01:14:21
【问题描述】:
我得到了一个结构列(来自 json)与这个架构:
struct_col_name
| |-- 2053771759: struct (nullable = true)
| | |-- col1: long (nullable = true)
| | |-- col2: string (nullable = true)
| | |-- col3: long (nullable = true)
| | |-- col4: string (nullable = true)
| |-- 2053771760: struct (nullable = true)
| | |-- col1: long (nullable = true)
| | |-- col2: string (nullable = true)
| | |-- col3: long (nullable = true)
| | |-- col4: string (nullable = true)
| |-- 2053771761: struct (nullable = true)
| | |-- col1: long (nullable = true)
| | |-- col2: string (nullable = true)
| | |-- col3: long (nullable = true)
| | |-- col4: string (nullable = true)
由于所有内部 strcuts 都具有相同的字段,我想将架构转换为类似的内容,并将id(例如2053771759)添加为每个元素的字段。
通过这样做,我将能够将列分解为行。
struct_col_name
| |-- element: struct: struct (nullable = true)
| | | |-- col1: long (nullable = true)
| | | |-- col2: string (nullable = true)
| | | |-- col3: long (nullable = true)
| | | |-- col4: string (nullable = true)
| | | |-- id: long (nullable = true)
知道我该怎么做吗?还是用其他方式炸开柱子?
【问题讨论】:
标签: python apache-spark pyspark apache-spark-sql