有没有更好的方法来转换数组 到阵列 在pyspark

问题描述 投票:2回答:1

一个非常庞大的DataFrame with schema:

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

但这种方式太贵了。

apache-spark pyspark apache-spark-sql spark-dataframe
1个回答
7
投票

您可以简单地将ext列转换为字符串数组

df = source.withColumn("ext", source.ext.cast("array<string>"))
df.printSchema()
df.show()
© www.soinside.com 2019 - 2024. All rights reserved.