struct(x as poi,(i+1) as poi_rn))""")))\.select('pois2.*','pois').show(truncate=Fa_sparks">
赞
踩
对于Spark2.4+,可以使用带高阶函数 transformation的explode。
from pyspark.sql import functions as F
demo.select('pois').withColumn("pois2", F.explode(F.expr("""transform(pois,(x,i)-> struct(x as poi,(i+1) as poi_rn))""")))\
.select('pois2.*','pois').show(truncate=False)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。