org.eigenbase.oj.rex
Interface OJAggImplementor

All Known Implementing Classes:
OJRexImplementorTableImpl.OJBasicAggImplementor, OJRexImplementorTableImpl.OJCountAggImplementor, OJRexImplementorTableImpl.OJMinMaxAggImplementor, OJRexImplementorTableImpl.OJSumAggImplementor

public interface OJAggImplementor

Translates a call to an Aggregation into OpenJava code.

Implementors are held in a OJRexImplementorTable.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/oj/rex/OJAggImplementor.java#12 $
Author:
jhyde

Method Summary
 boolean canMerge()
          Returns whether this aggregation can merge together two accumulators.
 void implementMerge(JavaRelImplementor implementor, RelNode rel, Expression accumulator, Expression otherAccumulator)
          Generates (into the current statement list, gleaned by calling implementor's JavaRelImplementor.getStatementList() method) code to merge two accumulators.
 void implementNext(JavaRelImplementor implementor, JavaRel rel, Expression accumulator, AggregateCall call)
          Generates (into the current statement list, gleaned by calling implementor's JavaRelImplementor.getStatementList() method) the piece of code which gets called each time an extra row is seen.
 Expression implementResult(JavaRelImplementor implementor, Expression accumulator, AggregateCall call)
          Generates the expression which gets called when a total is complete.
 Expression implementStart(JavaRelImplementor implementor, JavaRel rel, AggregateCall call)
          Generates the expression which gets called when a new total is created.
 Expression implementStartAndNext(JavaRelImplementor implementor, JavaRel rel, AggregateCall call)
          Generates code to create a new total and to add the first value.
 

Method Detail

implementStart

Expression implementStart(JavaRelImplementor implementor,
                          JavaRel rel,
                          AggregateCall call)
Generates the expression which gets called when a new total is created. For sum(x), this looks like new saffron.runtime.Holder.int_Holder(0).


implementStartAndNext

Expression implementStartAndNext(JavaRelImplementor implementor,
                                 JavaRel rel,
                                 AggregateCall call)
Generates code to create a new total and to add the first value. For sum(x), this looks like new saffron.runtime.Holder.int_Holder(x).


canMerge

boolean canMerge()
Returns whether this aggregation can merge together two accumulators.

For example, COUNT can (you just add the accumulators); AVG and MEDIAN cannot.

Returns:
whether this aggregation can merge together two accumulators

implementMerge

void implementMerge(JavaRelImplementor implementor,
                    RelNode rel,
                    Expression accumulator,
                    Expression otherAccumulator)
Generates (into the current statement list, gleaned by calling implementor's JavaRelImplementor.getStatementList() method) code to merge two accumulators. For sum(x), this looks like ((saffron.runtime.Holder.int_Holder) accumulator).value += ((saffron.runtime.Holder.int_Holder) other).value.

The method is only called if canMerge() returns true.

Parameters:
implementor - a callback object which knows how to generate things
rel - the relational expression which is generating this code
accumulator - the expression which holds the total
otherAccumulator - accumulator to merge in

implementNext

void implementNext(JavaRelImplementor implementor,
                   JavaRel rel,
                   Expression accumulator,
                   AggregateCall call)
Generates (into the current statement list, gleaned by calling implementor's JavaRelImplementor.getStatementList() method) the piece of code which gets called each time an extra row is seen. For sum(x), this looks like ((org.eigenbase.runtime.Holder.int_Holder) accumulator).value += x.

Parameters:
implementor - a callback object which knows how to generate things
rel - the relational expression which is generating this code
accumulator - the expression which holds the total
call - the ordinals of the fields of the child row which are arguments to this aggregation

implementResult

Expression implementResult(JavaRelImplementor implementor,
                           Expression accumulator,
                           AggregateCall call)
Generates the expression which gets called when a total is complete. For sum(x), this looks like ((saffron.runtime.Holder.int_Holder) accumulator).value.