Class RelFieldTrimmer

All Implemented Interfaces:

public class RelFieldTrimmer extends Object implements ReflectiveVisitor
Transformer that walks over a tree of relational expressions, replacing each RelNode with a 'slimmed down' relational expression that projects only the columns required by its consumer.

Uses multi-methods to fire the right rule for each type of relational expression. This allows the transformer to be extended without having to add a new method to RelNode, and without requiring a collection of rule classes scattered to the four winds.

REVIEW: jhyde, 2009/7/28: Is sql2rel the correct package for this class? Trimming fields is not an essential part of SQL-to-Rel translation, and arguably belongs in the optimization phase. But this transformer does not obey the usual pattern for planner rules; it is difficult to do so, because each RelNode needs to return a different set of fields after trimming.

TODO: Change 2nd arg of the trimFields(org.apache.calcite.rel.RelNode, org.apache.calcite.util.ImmutableBitSet, java.util.Set<org.apache.calcite.rel.type.RelDataTypeField>) method from BitSet to Mapping. Sometimes it helps the consumer if you return the columns in a particular order. For instance, it may avoid a project at the top of the tree just for reordering. Could ease the transition by writing methods that convert BitSet to Mapping and vice versa.