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 Aggregate.Call, in an Aggregate relational operator.

To help you understand the terminology, here are some analogies: an Aggregation is analogous to a OJMethod, whereas a Aggregate.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 (Rel).

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

Method Summary
 boolean canMerge()
          Whether this aggregation can merge together two accumulators.
 OJClass[] getParameterTypes()
           
 OJClass getReturnType()
           
 void implementMerge(Implementor implementor, Rel rel, Expression accumulator, Expression otherAccumulator)
          Generates (into the current statement list, gleaned by calling implementor's Implementor.getStatementList() method) code to merge two accumulators.
 void implementNext(Implementor implementor, Rel rel, Expression accumulator, int[] args)
          Generates (into the current statement list, gleaned by calling implementor's Implementor.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(Implementor implementor, Rel rel, int[] args)
          Generates the expression which gets called when a new total is created.
 Expression implementStartAndNext(Implementor implementor, Rel rel, int[] args)
          Generates code to create a new total and to add the first value.
 

Method Detail

getReturnType

public OJClass getReturnType()

getParameterTypes

public OJClass[] getParameterTypes()

canMerge

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


implementStart

public Expression implementStart(Implementor implementor,
                                 Rel 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(Implementor implementor,
                                        Rel 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).


implementNext

public void implementNext(Implementor implementor,
                          Rel rel,
                          Expression accumulator,
                          int[] args)
Generates (into the current statement list, gleaned by calling implementor's Implementor.getStatementList() method) the piece of code which gets called each time an extra row is seen. For sum(x), this looks like ((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

implementMerge

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

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.


SourceForge.net_Logo