Spark SQL 聚合实现原理
Aggregation Mode
1.Partial
2.final
3.complete
4.partial merge
AggragateFunction
DecalarativeAggragate: 用Expression 描述逻辑,执行时用codegen生成Project 进行计算
ImperativeAggragte:定义方法,命令式地执行计算逻辑,聚合物理算子需显示调用这些方法
TypedImperativeAggregate:可以用任务JVM对象作为buffer,写shuffle前需要序列化,读shuffle后需要反序列化
和聚合相关的一些优化
RemoveLiteralFromGroupExpression 消除groupingKey中的常量 (和重复表达式)
| EliminateDuplicateAgg 将某些场景下冗余的多次aggregate消除 Aggregate | – Union | – Aggregate | – Other |
RemoveFoldableAttributesFromAggregate 如果groupingKey中有通过filter保证值是确定的情况则可以消除 select count(1) from r where id1 = 1 group by id1,id2
EliminatePartialAgg Distribution 已满足的场景下将 partial agg 和filter agg 合并成一个complete agg
HashAggregateExec 中退化为project 聚合收敛比过低时,将聚合退化为project,节省内存和计算
Spark AE以及build left side原理
文档信息
- 本文作者:Jessica
- 本文链接:https://jessica0530.github.io/2021/03/14/Spark-%E4%BC%98%E5%8C%96/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)