Search in sources :

Example 1 with MaterializedViewSubstitutionVisitor

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);
                }
            }
        }
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RelOptMaterialization(org.apache.calcite.plan.RelOptMaterialization) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) MaterializedViewSubstitutionVisitor(org.apache.calcite.plan.MaterializedViewSubstitutionVisitor)

Aggregations

MaterializedViewSubstitutionVisitor (org.apache.calcite.plan.MaterializedViewSubstitutionVisitor)1 RelOptMaterialization (org.apache.calcite.plan.RelOptMaterialization)1 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)1 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)1 VolcanoPlanner (org.apache.calcite.plan.volcano.VolcanoPlanner)1 RelNode (org.apache.calcite.rel.RelNode)1