pyspark udf返回值

时间:2019-11-20 22:18:51

标签: pyspark user-defined-functions

我创建了一个返回列表列表的udf(内置列表对象)。我将返回的值保存到新列中,但是发现它已转换为字符串。我需要它作为列表列表来激活posexplode,正确的方法是什么?

def conc(hashes, band_width):   
    ...
    ...
    return combined_chunks #it's type: list[list[float]]

concat = udf(conc)

#bands column becomes a string
mh2 = mh1.withColumn("bands", concat(col('hash'),lit(bandwidth)))

1 个答案:

答案 0 :(得分:1)

我解决了:

concat = udf(conc,ArrayType(VectorUDT()))

简而言之:使用Vectors.dense返回密集向量的列表。