public class RelFieldTrimmer extends Object implements ReflectiveVisitor
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.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
RelFieldTrimmer.TrimResult
Result of an attempt to trim columns from a relational expression.
|
| Constructor and Description |
|---|
RelFieldTrimmer(@Nullable SqlValidator validator,
RelBuilder relBuilder)
Creates a RelFieldTrimmer.
|
RelFieldTrimmer(@Nullable SqlValidator validator,
RelOptCluster cluster,
RelFactories.ProjectFactory projectFactory,
RelFactories.FilterFactory filterFactory,
RelFactories.JoinFactory joinFactory,
RelFactories.SortFactory sortFactory,
RelFactories.AggregateFactory aggregateFactory,
RelFactories.SetOpFactory setOpFactory)
Deprecated.
|
public RelFieldTrimmer(@Nullable SqlValidator validator, RelBuilder relBuilder)
validator - Validator@Deprecated public RelFieldTrimmer(@Nullable SqlValidator validator, RelOptCluster cluster, RelFactories.ProjectFactory projectFactory, RelFactories.FilterFactory filterFactory, RelFactories.JoinFactory joinFactory, RelFactories.SortFactory sortFactory, RelFactories.AggregateFactory aggregateFactory, RelFactories.SetOpFactory setOpFactory)
public RelNode trim(RelNode root)
We presume that all fields of the relational expression are wanted by its consumer, so only trim fields that are not used within the tree.
root - Root node of relational expressionprotected RelFieldTrimmer.TrimResult trimChild(RelNode rel, RelNode input, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
rel - Relational expressioninput - Input relational expression, whose fields to trimfieldsUsed - Bitmap of fields needed by the consumerprotected RelFieldTrimmer.TrimResult trimChildRestore(RelNode rel, RelNode input, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
Sounds pointless? It causes unused fields to be removed further down the tree (towards the leaves), but it ensure that the consuming relational expression continues to see the same fields.
rel - Relational expressioninput - Input relational expression, whose fields to trimfieldsUsed - Bitmap of fields needed by the consumerprotected final RelFieldTrimmer.TrimResult dispatchTrimFields(RelNode rel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(org.apache.calcite.rel.RelNode, org.apache.calcite.util.ImmutableBitSet, java.util.Set<org.apache.calcite.rel.type.RelDataTypeField>), or the appropriate method for the type
of the rel parameter, using multi-method dispatch.rel - Relational expressionfieldsUsed - Bitmap of fields needed by the consumerprotected RelFieldTrimmer.TrimResult result(RelNode rel, Mapping mapping, RelNode oldRel)
protected RelFieldTrimmer.TrimResult result(RelNode r, Mapping mapping)
public RelFieldTrimmer.TrimResult trimFields(RelNode rel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
ReflectiveVisitor.
This method is invoked reflectively, so there may not be any apparent
calls to it. The class (or derived classes) may contain overloads of
this method with more specific types for the rel parameter.
Returns a pair: the relational expression created, and the mapping between the original fields and the fields of the newly created relational expression.
rel - Relational expressionfieldsUsed - Fields needed by the consumerpublic RelFieldTrimmer.TrimResult trimFields(Calc calc, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalCalc.public RelFieldTrimmer.TrimResult trimFields(Project project, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalProject.protected RelFieldTrimmer.TrimResult dummyProject(int fieldCount, RelNode input)
fieldCount - Number of fields in the original relational expressioninput - Trimmed inputprotected RelFieldTrimmer.TrimResult dummyProject(int fieldCount, RelNode input, @Nullable RelNode originalRelNode)
fieldCount - Number of fields in the original relational expressioninput - Trimmed inputoriginalRelNode - Source RelNode for hint propagation (or null if no propagation needed)public RelFieldTrimmer.TrimResult trimFields(Filter filter, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalFilter.public RelFieldTrimmer.TrimResult trimFields(Sort sort, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
Sort.public RelFieldTrimmer.TrimResult trimFields(Exchange exchange, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
public RelFieldTrimmer.TrimResult trimFields(SortExchange sortExchange, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
public RelFieldTrimmer.TrimResult trimFields(Join join, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalJoin.public RelFieldTrimmer.TrimResult trimFields(SetOp setOp, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
SetOp (Only UNION ALL is supported).public RelFieldTrimmer.TrimResult trimFields(Aggregate aggregate, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalAggregate.public RelFieldTrimmer.TrimResult trimFields(LogicalTableModify modifier, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalTableModify.public RelFieldTrimmer.TrimResult trimFields(LogicalTableFunctionScan tabFun, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalTableFunctionScan.public RelFieldTrimmer.TrimResult trimFields(LogicalValues values, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalValues.protected Mapping createMapping(ImmutableBitSet fieldsUsed, int fieldCount)
public RelFieldTrimmer.TrimResult trimFields(TableScan tableAccessRel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
trimFields(RelNode, ImmutableBitSet, Set) for
LogicalTableScan.Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.