一个非常大的带有模式的数据帧:
root
|-- id: string (nullable = true)
|-- ext: array (nullable = true)
| |-- element: integer (containsNull = true)
到目前为止,我尝试explode
数据,然后collect_list
:
select
id,
collect_list(cast(item as string))
from default.dual
lateral view explode(ext) t as item
group by
id
但这种方式太宽泛了。
您可以简单地将ext
列转换为字符串数组
df = source.withColumn("ext", source.ext.cast("array<string>"))
df.printSchema()
df.show()