org.eigenbase.rel.rules
Class ReduceAggregatesRule

java.lang.Object
  extended by org.eigenbase.relopt.RelOptRule
      extended by org.eigenbase.rel.rules.ReduceAggregatesRule

public class ReduceAggregatesRule
extends RelOptRule

Rule to reduce aggregates to simpler forms. Currently only AVG(x) to SUM(x)/COUNT(x), but eventually will handle others such as STDDEV.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/rel/rules/ReduceAggregatesRule.java#10 $
Author:
John V. Sichi

Field Summary
static ReduceAggregatesRule instance
          The singleton.
 
Fields inherited from class org.eigenbase.relopt.RelOptRule
ANY, description, operands
 
Constructor Summary
protected ReduceAggregatesRule(RelOptRuleOperand operand)
           
 
Method Summary
private  RelDataType getField(RelNode relNode, int i)
           
protected  AggregateRelBase newAggregateRel(AggregateRelBase oldAggRel, List<AggregateCall> newCalls)
          Do a shallow clone of oldAggRel and update aggCalls.
 void onMatch(RelOptRuleCall ruleCall)
          Receives notification about a rule match.
private  void reduceAverages(RelOptRuleCall ruleCall, AggregateRelBase oldAggRel)
           
 
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 ReduceAggregatesRule instance
The singleton.

Constructor Detail

ReduceAggregatesRule

protected ReduceAggregatesRule(RelOptRuleOperand operand)
Method Detail

onMatch

public void onMatch(RelOptRuleCall ruleCall)
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:
ruleCall - Rule call
See Also:
RelOptRule.matches(RelOptRuleCall)

reduceAverages

private void reduceAverages(RelOptRuleCall ruleCall,
                            AggregateRelBase oldAggRel)

newAggregateRel

protected AggregateRelBase newAggregateRel(AggregateRelBase oldAggRel,
                                           List<AggregateCall> newCalls)
Do a shallow clone of oldAggRel and update aggCalls. Could be refactored into AggregateRelBase and subclasses - but it's only needed for some subclasses.

Parameters:
oldAggRel - AggregateRel to clone.
newCalls - New list of AggregateCalls
Returns:
shallow clone with new list of AggregateCalls.

getField

private RelDataType getField(RelNode relNode,
                             int i)