【发布时间】:2021-07-05 12:35:00
【问题描述】:
我正在尝试在分区数据框中添加包含 row_num 的列。
最初,我从 Azure blob 读取我的增量数据:
var df = spark.read.format("delta").load(path)
此数据按日期列分区:
df.rdd.getNumPartitions
res28: Int = 5
所以当我尝试添加 row_num 列时:
df=df.withColumn("id", monotonically_increasing_id()
它生成 5 个不同的序列(每个分区一个),这显然不是我需要的。
我的问题是:无论如何要在分区数据帧上生成正确的行数列吗?
我正在考虑使用这样的东西:
df=df.coalesce(1).withColumn("id", monotonically_increasing_id()
但我不知道如果这是最佳实践,我的其余代码是否安全。
谢谢!
【问题讨论】:
标签: scala apache-spark row-number