在 pyspark 中有没有更好的方法将 Array<int> 转换为 Array<String>
Is there any better way to convert Array<int> to Array<String> in pyspark
一个非常大 DataFrame 具有架构:
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()
一个非常大 DataFrame 具有架构:
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()