【spark】dataframe慎用limit

官方:limit通常和order by一起使用,保证结果是确定的

limit 会有两个步骤:

  1. LocalLimit ,发生在每个partition
  2. 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

相关推荐
SelectDB2 小时前
阶跃星辰基于 SelectDB 构建 PB 级 Agent 可观测平台
大数据·数据库·aigc
大大大大晴天3 天前
Hudi技术内幕:RecordPayload到RecordMerger
大数据
SelectDB4 天前
秒级弹性、最高降本 70%:SelectDB Serverless 如何重塑云数仓资源效率
大数据·后端·云原生
WhoAmI4 天前
MapReduce框架原理解析一:InputFormat
大数据·hadoop
WhoAmI4 天前
MapReduce框架原理解析三:OutputFormat
大数据·hadoop
WhoAmI4 天前
MapReduce框架原理解析二:Shuffle
大数据·hadoop
大大大大晴天5 天前
Hudi技术内幕:Key Generation原理与实践
大数据
得物技术8 天前
从埋点需求到规则资产:Hermes Agent 重构得物数仓工作流
大数据·llm·ai编程
久美子8 天前
AI驱动数仓建设的Harness工程实践——本体建模、知识分层与上下文工程
大数据
大树889 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai