一、概述

二、实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def apply(plan: LogicalPlan): LogicalPlan = {
val pushdownRules = Seq[LogicalPlan => LogicalPlan] (
createScanBuilder,
pushDownSample,
pushDownFilters,
pushDownAggregates,
pushDownLimitAndOffset,
buildScanWithPushedAggregate,
pruneColumns)

pushdownRules.foldLeft(plan) { (newPlan, pushDownRule) =>
pushDownRule(newPlan)
}
}

2.1. createScanBuilder()

$createScanBuilder()$ 方法对 DataSourceV2Relation 类型转换为 ScanBuilderHolder,后续的 $pushDownFilters()$ 、$pushDownAggregates()$ 规则则是基于 ScanBuilderHolder 来进行转换

如果有遇到 ScanBuilderHolder 类型才会进行 DataSource V2 特有的规则转换~

所以DataSourceV2Relation是从哪里来的是关键~🤔️?
在 RULE ResolveRelations 中会进行 UnresolvedRelation 到 DataSourceV2Relation 或是 UnresolvedCatalogRelation 的转换:

1
2
3
4
private def createScanBuilder(plan: LogicalPlan) = plan.transform {
case r: DataSourceV2Relation =>
ScanBuilderHolder(r.output, r, r.table.asReadable.newScanBuilder(r.options))
}