Search in sources :

Example 1 with RelTraitPropagationVisitor

use of org.apache.calcite.plan.RelTraitPropagationVisitor in project calcite by apache.

the class VolcanoRuleCall method transformTo.

// ~ Methods ----------------------------------------------------------------
// implement RelOptRuleCall
public void transformTo(RelNode rel, Map<RelNode, RelNode> equiv) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Transform to: rel#{} via {}{}", rel.getId(), getRule(), equiv.isEmpty() ? "" : " with equivalences " + equiv);
        if (generatedRelList != null) {
            generatedRelList.add(rel);
        }
    }
    try {
        // It's possible that rel is a subset or is already registered.
        // Is there still a point in continuing? Yes, because we might
        // discover that two sets of expressions are actually equivalent.
        // Make sure traits that the new rel doesn't know about are
        // propagated.
        RelTraitSet rels0Traits = rels[0].getTraitSet();
        new RelTraitPropagationVisitor(getPlanner(), rels0Traits).go(rel);
        if (LOGGER.isTraceEnabled()) {
            // Cannot call RelNode.toString() yet, because rel has not
            // been registered. For now, let's make up something similar.
            String relDesc = "rel#" + rel.getId() + ":" + rel.getRelTypeName();
            LOGGER.trace("call#{}: Rule {} arguments {} created {}", id, getRule(), Arrays.toString(rels), relDesc);
        }
        if (volcanoPlanner.listener != null) {
            RelOptListener.RuleProductionEvent event = new RelOptListener.RuleProductionEvent(volcanoPlanner, rel, this, true);
            volcanoPlanner.listener.ruleProductionSucceeded(event);
        }
        // don't register twice and cause churn.
        for (Map.Entry<RelNode, RelNode> entry : equiv.entrySet()) {
            volcanoPlanner.ensureRegistered(entry.getKey(), entry.getValue(), this);
        }
        volcanoPlanner.ensureRegistered(rel, rels[0], this);
        rels[0].getCluster().invalidateMetadataQuery();
        if (volcanoPlanner.listener != null) {
            RelOptListener.RuleProductionEvent event = new RelOptListener.RuleProductionEvent(volcanoPlanner, rel, this, false);
            volcanoPlanner.listener.ruleProductionSucceeded(event);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error occurred while applying rule " + getRule(), e);
    }
}
Also used : RelOptListener(org.apache.calcite.plan.RelOptListener) RelTraitPropagationVisitor(org.apache.calcite.plan.RelTraitPropagationVisitor) RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 RelOptListener (org.apache.calcite.plan.RelOptListener)1 RelTraitPropagationVisitor (org.apache.calcite.plan.RelTraitPropagationVisitor)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelNode (org.apache.calcite.rel.RelNode)1