背景
本文基于delta 0.7.0
spark 3.0.1
spark 3.x引入了动态分区裁剪,今天我们分析以下代码是怎么实现的
分析
直接定位到PartitionPruning.applyPartitionPruning是逻辑计划的规则
override def apply(plan: LogicalPlan): LogicalPlan = plan match {
// Do not rewrite subqueries.
case s: Subquery if s.correlated => plan
case _ if !SQLConf.get.dynamicPartitionPruningEnabled => plan
case _ => prune(plan)
}
- 当是该逻辑计划是子查询且该子查询是相关的,则直接跳过,因为相关的子查询将会被重写到join条件中
- 如果没有开启动态分区,则直接跳过
- 其他条件则会跳到下一步
下一步的条件,则是会判断是否是包含join操作,如果是join操作才会进行后续的操作:
private def prune(plan: LogicalPlan): LogicalPlan = {
plan transformUp {
// skip this rule if there's already a DPP subquery on the LHS of a join
case j @ Join(Filter(_: DynamicPruningSubquery, _), _, _, _, _) => j
case j @ Join(_, Filter(_: DynamicPruningSubquery, _), _, _, _) => j
case j @ Join(le

本文深入解析Spark 3.0.1中的动态分区裁剪机制,重点在于PartitionPruning.applyPartitionPruning逻辑。当SQLConf动态分区裁剪启用时,针对Join操作,提取等值连接键并检查是否能用于动态裁剪。通过pruningHasBenefit方法评估过滤效果,优化左或右连接表,减少不必要的分区扫描。这一过程涉及到HadoopFsRelation、DynamicPruningSubquery等概念,旨在提高查询效率。
最低0.47元/天 解锁文章
1064

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



