Apache spark Pyspark将列转换为数组并分解值

Apache spark Pyspark将列转换为数组并分解值,apache-spark,pyspark,Apache Spark,Pyspark,我正在尝试将列转换为行。 首先将列合并到数组中 第二步是分解数组列 “爆炸”功能不起作用 >>> filteredPaths1.select( array ( concat( col("v1.id"),lit(","),col("v2.id"),lit(",") ,col("v2.id") )).alias("test") ).printSchem

我正在尝试将列转换为行。 首先将列合并到数组中 第二步是分解数组列

“爆炸”功能不起作用

>>> filteredPaths1.select(   array ( concat( col("v1.id"),lit(","),col("v2.id"),lit(",") ,col("v2.id") )).alias("test")     ).printSchema()
root
 |-- test: array (nullable = false)
 |    |-- element: string (containsNull = true)
数组列中的值-

>>> filteredPaths1.select(   array ( concat( col("v1.id"),lit(","),col("v2.id"),lit(",") ,col("v2.id") )).alias("test")     ).show(10,False)
+--------------------------------------------------------------+                ]
|test                                                          |
+--------------------------------------------------------------+
|[Sorter_SAMPLE_CUSTOMER,Join_Source_Target,Join_Source_Target]|
+--------------------------------------------------------------+
但是,当尝试分解数组列时,它不会创建新行,只是给出相同的输出-

>>> filteredPaths1.select(   explode (array ( concat( col("v1.id"),lit(","),col("v2.id"),lit(",") ,col("v2.id") )).alias("test") )    ).show(10,False)
+------------------------------------------------------------+                  ]
|col                                                         |
+------------------------------------------------------------+
|Sorter_SAMPLE_CUSTOMER,Join_Source_Target,Join_Source_Target|
+------------------------------------------------------------+
是否有任何原因导致explode无法工作?

因为您正在使用arrayconcat。。表示一个值的数组&分解此数组,您将只得到一行,即相同的值

使用拆分而不是数组


感谢您指出这一点,我已经删除了concat所有在一起,它也很好地工作,但感谢提供解决方案。从三个字符串中创建一个字符串列。
filteredPaths1.select(explode(split(concat_ws(",",col("v1.id"),col("v2.id"),col("v2.id")),",")).alias("test"))