use of org.apache.calcite.plan.MaterializedViewSubstitutionVisitor in project calcite by apache.
the class MaterializedViewFilterScanRule method apply.
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) {
RelOptPlanner planner = call.getPlanner();
List<RelOptMaterialization> materializations = (planner instanceof VolcanoPlanner) ? ((VolcanoPlanner) planner).getMaterializations() : ImmutableList.<RelOptMaterialization>of();
if (!materializations.isEmpty()) {
RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan));
List<RelOptMaterialization> applicableMaterializations = RelOptMaterializations.getApplicableMaterializations(root, materializations);
for (RelOptMaterialization materialization : applicableMaterializations) {
if (RelOptUtil.areRowTypesEqual(scan.getRowType(), materialization.queryRel.getRowType(), false)) {
RelNode target = materialization.queryRel;
final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext());
hepPlanner.setRoot(target);
target = hepPlanner.findBestExp();
List<RelNode> subs = new MaterializedViewSubstitutionVisitor(target, root).go(materialization.tableRel);
for (RelNode s : subs) {
call.transformTo(s);
}
}
}
}
}
Aggregations