net.sf.saffron.oj.rel
Class BuiltinAggregation

java.lang.Object
  |
  +--net.sf.saffron.oj.rel.BuiltinAggregation
All Implemented Interfaces:
Aggregation
Direct Known Subclasses:
BuiltinAggregation.Count, BuiltinAggregation.MinMax, BuiltinAggregation.Sum

public abstract class BuiltinAggregation
extends Object
implements Aggregation

BuiltinAggregation is a basic aggregator for which special code is generated.

Since:
3 February, 2002
Version:
$Id: //open/saffron/src/net/sf/saffron/oj/rel/BuiltinAggregation.java#3 $
Author:
jhyde

Nested Class Summary
(package private) static class BuiltinAggregation.Count
          Count is an aggregator which returns the number of rows which have gone into it.
(package private) static class BuiltinAggregation.MinMax
          MinMax implements the "min" and "max" aggregator functions, returning the returns the smallest/largest of the values which go into it.
(package private) static class BuiltinAggregation.Sum
          Sum is an aggregator which returns the sum of the values which go into it.
 
Constructor Summary
BuiltinAggregation()
           
 
Method Summary
 boolean canMerge()
          Whether this aggregation can merge together two accumulators.
static int count()
           
static int count(double v)
           
static int count(int v)
           
static int count(Object v)
           
static BuiltinAggregation create(String name, OJClass[] argTypes)
          Creates a BuiltinAggregation with a given name and argument types.
(package private) abstract  String getName()
           
protected abstract  OJClass[] getParameterTypes()
           
 SaffronType[] getParameterTypes(SaffronTypeFactory typeFactory)
           
protected abstract  OJClass getReturnType()
           
 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.
 Expression implementStartAndNext(RelImplementor implementor, SaffronRel rel, int[] args)
          This is a default implementation of Aggregation.implementStartAndNext(net.sf.saffron.opt.RelImplementor, net.sf.saffron.rel.SaffronRel, int[]); particular derived classes may do better.
static OJMethod lookup(String name, OJClass[] argTypes)
          Returns the builtin aggregator with a given name, if there is one.
static double max(double v)
           
static double max(int v)
           
static int max(Object v)
           
static double min(double v)
           
static double min(int v)
           
static int min(Object v)
           
static double sum(double v)
           
static int sum(int v)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.saffron.rel.Aggregation
implementNext, implementResult, implementStart
 

Constructor Detail

BuiltinAggregation

public BuiltinAggregation()
Method Detail

count

public static int count()

count

public static int count(Object v)

count

public static int count(int v)

count

public static int count(double v)

create

public static BuiltinAggregation create(String name,
                                        OJClass[] argTypes)
Creates a BuiltinAggregation with a given name and argument types.


getParameterTypes

public SaffronType[] getParameterTypes(SaffronTypeFactory typeFactory)
Specified by:
getParameterTypes in interface Aggregation

getReturnType

public SaffronType getReturnType(SaffronTypeFactory typeFactory)
Specified by:
getReturnType 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

implementMerge

public void implementMerge(RelImplementor implementor,
                           SaffronRel rel,
                           Expression accumulator,
                           Expression otherAccumulator)
Description copied from interface: Aggregation
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 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

implementStartAndNext

public Expression implementStartAndNext(RelImplementor implementor,
                                        SaffronRel rel,
                                        int[] args)
This is a default implementation of Aggregation.implementStartAndNext(net.sf.saffron.opt.RelImplementor, net.sf.saffron.rel.SaffronRel, int[]); particular derived classes may do better.

Specified by:
implementStartAndNext in interface Aggregation

lookup

public static OJMethod lookup(String name,
                              OJClass[] argTypes)
Returns the builtin aggregator with a given name, if there is one. Note that there is only one builtin aggregator with a particular name ("sum", say), but a particular instance may have different parameter types.


max

public static int max(Object v)

max

public static double max(int v)

max

public static double max(double v)

min

public static int min(Object v)

min

public static double min(int v)

min

public static double min(double v)

sum

public static int sum(int v)

sum

public static double sum(double v)

getParameterTypes

protected abstract OJClass[] getParameterTypes()

getReturnType

protected abstract OJClass getReturnType()

getName

abstract String getName()

SourceForge.net_Logo