2024-10-04 01:30:53 发布
网友
我想写一个数据帧到hdfs。但是随机排序非常慢,尽管只有1700万个数据行。在
df = df.withColumn('random_index',rand()) df = df.orderBy('random_index') df.write.csv('hdfs:///user/yananc/yanan_gbdt_dnn', sep=',')
有没有什么快速有效的方法来实现这一点?在
使用orderBy将跨数据帧的所有分区对行进行排序。因为您只想对行进行无序处理,所以可以考虑改用sortWithinPartitions。此方法不需要对数据进行洗牌,因此速度更快:
orderBy
sortWithinPartitions
df.sortWithinPartitions(rand())
当然,根据数据帧的不同,这不会对数据给出完全随机的顺序。这取决于行在分区中的分布方式。在
使用
orderBy
将跨数据帧的所有分区对行进行排序。因为您只想对行进行无序处理,所以可以考虑改用sortWithinPartitions
。此方法不需要对数据进行洗牌,因此速度更快:当然,根据数据帧的不同,这不会对数据给出完全随机的顺序。这取决于行在分区中的分布方式。在
相关问题 更多 >
编程相关推荐