org.eigenbase.rel.rules
Class PullConstantsThroughAggregatesRule

java.lang.Object
  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.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/rel/rules/PullConstantsThroughAggregatesRule.java#8 $
Author:
jhyde

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

instance

public static final PullConstantsThroughAggregatesRule instance
The singleton.

Constructor Detail

PullConstantsThroughAggregatesRule

private PullConstantsThroughAggregatesRule()
Private: use singleton

Method Detail

onMatch

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
Parameters:
call - Rule call
See Also:
RelOptRule.matches(RelOptRuleCall)

createProjection

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].

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