官方:limit通常和order by一起使用,保证结果是确定的
limit 会有两个步骤:
- LocalLimit ,发生在每个partition
- GlobalLimit,发生shuffle,聚合到一个parttion
当提取的n大时,第二步是比较耗时的
== Physical Plan ==
Execute InsertIntoHadoopFsRelationCommand (5)
+- * GlobalLimit (4)
+- Exchange (3)
+- * LocalLimit (2)
+- Scan csv (1)
如果对取样顺序没有要求,可用tablesample替代,使用详解。
== Physical Plan ==
Execute InsertIntoHadoopFsRelationCommand (3)
+- * Sample (2)
+- Scan csv (1)
参考
官方
Stop using the LIMIT clause wrong with Spark
DataFrame orderBy followed by limit in Spark
本文讨论了在SparkDataFrame中正确使用`limit`和`orderby`的方法,强调了LocalLimit和GlobalLimit的区别,以及如何通过tablesample代替全表扫描来提高性能。作者还提到了`PhysicalPlan`中的执行命令结构,如Exchange和Scancsv操作。
1145

被折叠的 条评论
为什么被折叠?



