net.sf.saffron.rel
Interface Aggregation

All Known Implementing Classes:
BuiltinAggregation, ExtenderAggregation

public interface Aggregation

An Aggregation aggregates a set of values into one value.

It is used, via a AggregateRel.Call, in an AggregateRel relational operator.

To help you understand the terminology, here are some analogies: an Aggregation is analogous to a OJMethod, whereas a AggregateRel.Call is analogous to a MethodCall. AggregationExtender has no direct analog in Java: it is more like a function object in JScript.

For user-defined aggregates, use you should generally use AggregationExtender; writing a new Aggregation is a complicated task, akin to writing a new relational operator (SaffronRel).

Since:
26 January, 2001
Version:
$Id: //open/saffron/src/net/sf/saffron/rel/Aggregation.java#5 $
Author:
jhyde
See Also:
AggregationExtender

Method Summary
 boolean canMerge()
          Whether this aggregation can merge together two accumulators.
 SaffronType[] getParameterTypes(SaffronTypeFactory typeFactory)
           
 SaffronType getReturnType(SaffronTypeFactory typeFactory)
           
 void implementMerge(RelImplementor implementor, SaffronRel rel, Expression accumulator, Expression otherAccumulator)
          Generates (into the current statement list, gleaned by calling implementor's RelImplementor.getStatementList() method) code to merge two accumulators.
 void implementNext(RelImplementor implementor, SaffronRel rel, Expression accumulator, int[] args)
          Generates (into the current statement list, gleaned by calling implementor's RelImplementor.getStatementList() method) the piece of code which gets called each time an extra row is seen.
 Expression implementResult(Expression accumulator)
          Generates the expression which gets called when a total is complete.
 Expression implementStart(RelImplementor implementor, SaffronRel rel, int[] args)
          Generates the expression which gets called when a new total is created.
 Expression implementStartAndNext(RelImplementor implementor, SaffronRel rel, int[] args)
          Generates code to create a new total and to add the first value.
 

Method Detail

getParameterTypes

public SaffronType[] getParameterTypes(SaffronTypeFactory typeFactory)

getReturnType

public SaffronType getReturnType(SaffronTypeFactory typeFactory)

canMerge

public boolean canMerge()
Whether this aggregation can merge together two accumulators. count can (you just add the accumulators); avg and Nth cannot.


implementMerge

public void implementMerge(RelImplementor implementor,
                           SaffronRel rel,
                           Expression accumulator,
                           Expression otherAccumulator)
Generates (into the current statement list, gleaned by calling implementor's RelImplementor.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

public void implementNext(RelImplementor implementor,
                          SaffronRel rel,
                          Expression accumulator,
                          int[] args)
Generates (into the current statement list, gleaned by calling implementor's RelImplementor.getStatementList() method) the piece of code which gets called each time an extra row is seen. For sum(x), this looks like ((net.sf.saffron.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
args - the ordinals of the fields of the child row which are arguments to this aggregation

implementResult

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


implementStart

public Expression implementStart(RelImplementor implementor,
                                 SaffronRel rel,
                                 int[] args)
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

public Expression implementStartAndNext(RelImplementor implementor,
                                        SaffronRel rel,
                                        int[] args)
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).


SourceForge.net_Logo