我有很多火花dataframes上,我需要做到以下几点:如何在火花数据框中强制重新分区?
1) load a single spark dataframe
2) select rows from it
3) merge it with all of the previous spark dataframes
现在,每个上面的操作需要不同的numberof分区。选择行需要很多分区,比如100个分区。合并需要非常少的分区,如10个分区。
所以,我真的希望它是这样工作的:
1) load a single spark dataframe
1.5) repartition into 100 partitions
2) select rows from it
2.5) repartition into 10 partitions
3) merge it with all of the previous spark dataframes
现在,我怎么用力这2和3之间步骤1和2之间,并在重新分区的?
我知道,当我打电话给data = data.repartition(7)
时,它被懒惰地评估,所以它只在实际保存时才重新分配。
所以,我一直在做这样的:
1) load a single spark dataframe
1.5) repartition into 100 partitions
1.75) `df.count()` *just* to force materialization
2) select rows from it
2.5) repartition into 10 partitions
2.75) `df.count()` *just* to force materialization
3) merge it with all of the previous spark dataframes
有没有更好的办法来迫使它在这里重新分区之间的?有没有比在数据框上运行count()
更好的方法?
但有没有什么办法可以避免像'first()'这样的无用操作,当我真的不在乎它从中输出什么?我只是想重新分配,但我不关心它实际输出的内容。有什么办法可以避免这种情况? – Sother
不幸的是,您不得不对数据框执行操作来应用所有转换,所以目前无法避免它。在答案中增加了一些信息。 – Shaido
@Sother更新了答案。 – Shaido