saffron.rel
Class ExtenderAggregation

java.lang.Object
  |
  +--saffron.rel.ExtenderAggregation
All Implemented Interfaces:
Aggregation

public class ExtenderAggregation
extends Object
implements Aggregation

ExtenderAggregation is an aggregation which works by instantiating a user-defined aggregation (AggregationExtender), as opposed to generating custom code.

Two bugs with the current implementation of implementStart(saffron.opt.Implementor, saffron.rel.Rel, int[]) etc. First, the aggregation expression should be evaluated only once -- when the query starts -- and stored in a variable. I guess it should be added to the environment holding the query.

Second, we pass real expressions as the values of the dummy arguments to implementStart(saffron.opt.Implementor, saffron.rel.Rel, int[]) and implementResult(openjava.ptree.Expression). This is inefficient, but moreover, it is conceivable that the expressions will not be valid in the scope where start and result are executed.

Since:
3 February, 2002
Version:
$Id: //open/saffron/src/main/saffron/rel/ExtenderAggregation.java#2 $
Author:
jhyde

Field Summary
(package private)  OJClass aggClazz
           
(package private)  Expression aggExp
           
(package private)  OJMethod aggregateMethod
           
(package private)  OJClass[] argTypes
           
(package private)  OJMethod mergeMethod
           
(package private)  OJMethod nextMethod
           
(package private)  OJMethod resultMethod
           
(package private)  OJMethod startMethod
           
 
Constructor Summary
(package private) ExtenderAggregation(Expression aggExp, Environment env, OJClass[] argTypes)
           
 
Method Summary
 boolean canMerge()
          Whether this aggregation can merge together two accumulators.
private static OJMethod findMethod(OJClass aggClazz, String name, OJClass[] argTypes, int extra, OJClass desiredType, boolean fail)
           
 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.
static boolean matches(OJClass aggClazz, OJClass[] argTypes)
          Returns whether this aggregation has an overloading which matches the given name and argument types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

aggExp

Expression aggExp

aggClazz

OJClass aggClazz

argTypes

OJClass[] argTypes

aggregateMethod

OJMethod aggregateMethod

startMethod

OJMethod startMethod

nextMethod

OJMethod nextMethod

mergeMethod

OJMethod mergeMethod

resultMethod

OJMethod resultMethod
Constructor Detail

ExtenderAggregation

ExtenderAggregation(Expression aggExp,
                    Environment env,
                    OJClass[] argTypes)
Method Detail

matches

public static boolean matches(OJClass aggClazz,
                              OJClass[] argTypes)
Returns whether this aggregation has an overloading which matches the given name and argument types.


findMethod

private static OJMethod findMethod(OJClass aggClazz,
                                   String name,
                                   OJClass[] argTypes,
                                   int extra,
                                   OJClass desiredType,
                                   boolean fail)

getReturnType

public OJClass getReturnType()
Specified by:
getReturnType in interface Aggregation

getParameterTypes

public OJClass[] getParameterTypes()
Specified by:
getParameterTypes in interface Aggregation

canMerge

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

Specified by:
canMerge in interface Aggregation

implementStart

public Expression implementStart(Implementor implementor,
                                 Rel rel,
                                 int[] args)
Description copied from interface: Aggregation
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).

Specified by:
implementStart in interface Aggregation

implementStartAndNext

public Expression implementStartAndNext(Implementor implementor,
                                        Rel rel,
                                        int[] args)
Description copied from interface: Aggregation
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).

Specified by:
implementStartAndNext in interface Aggregation

implementNext

public void implementNext(Implementor implementor,
                          Rel rel,
                          Expression accumulator,
                          int[] args)
Description copied from interface: Aggregation
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.

Specified by:
implementNext in interface Aggregation
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)
Description copied from interface: Aggregation
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 Aggregation.canMerge() returns true.

Specified by:
implementMerge in interface Aggregation
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)
Description copied from interface: Aggregation
Generates the expression which gets called when a total is complete. For sum(x), this looks like ((saffron.runtime.Holder.int_Holder) accumulator).value.

Specified by:
implementResult in interface Aggregation

SourceForge.net_Logo