Class PullConstantsThroughAggregatesRule

  extended by org.eigenbase.relopt.RelOptRule
      extended by org.eigenbase.rel.rules.PullConstantsThroughAggregatesRule

public class PullConstantsThroughAggregatesRule
extends RelOptRule

PullConstantsThroughAggregatesRule removes constant expressions from the group list of an AggregateRel.

Effect of the rule

Since the transformed relational expression has to match the original relational expression, the constants are placed in a projection above the reduced aggregate. If those constants are not used, another rule will remove them from the project.

AggregateRel needs its group columns to be on the prefix of its input relational expression. Therefore, if a constant is not on the trailing edge of the group list, removing it will leave a hole. In this case, the rule adds a project before the aggregate to reorder the columns, and permutes them back afterwards.

$Id: //open/dev/farrago/src/org/eigenbase/rel/rules/ $

Field Summary
static PullConstantsThroughAggregatesRule instance
          The singleton.
Fields inherited from class org.eigenbase.relopt.RelOptRule
ANY, description, operands
Constructor Summary
private PullConstantsThroughAggregatesRule()
          Private: use singleton
Method Summary
private static RelNode createProjection(Mapping mapping, RelNode child)
          Creates a projection which permutes the fields of a given relational expression.
 void onMatch(RelOptRuleCall call)
          Receives notification about a rule match.
Methods inherited from class org.eigenbase.relopt.RelOptRule
convert, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, mergeTraitsAndConvert, mergeTraitsAndConvert, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait

Field Detail


public static final PullConstantsThroughAggregatesRule instance
The singleton.

Constructor Detail


private PullConstantsThroughAggregatesRule()
Private: use singleton

Method Detail


public void onMatch(RelOptRuleCall call)
Description copied from class: RelOptRule
Receives notification about a rule match. At the time that this method is called, call.rels holds the set of relational expressions which match the operands to the rule; call.rels[0] is the root expression.

Typically a rule would check that the nodes are valid matches, creates a new expression, then calls back RelOptRuleCall.transformTo(org.eigenbase.rel.RelNode) to register the expression.

Specified by:
onMatch in class RelOptRule
call - Rule call
See Also:


private static RelNode createProjection(Mapping mapping,
                                        RelNode child)
Creates a projection which permutes the fields of a given relational expression.

For example, given a relational expression [A, B, C, D] and a mapping [2:1, 3:0], returns a projection [$3 AS C, $2 AS B].

mapping - Mapping to apply to source columns
child - Relational expression
Relational expressions with permutation applied