saffron
Class BuiltinAggregation

java.lang.Object
  |
  +--saffron.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/main/saffron/BuiltinAggregation.java#2 $
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()
           
 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.
 Expression implementStartAndNext(Implementor implementor, Rel rel, int[] args)
          This is a default implementation of Aggregation.implementStartAndNext(saffron.opt.Implementor, saffron.rel.Rel, 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 saffron.rel.Aggregation
getParameterTypes, getReturnType, implementNext, implementResult, implementStart
 

Constructor Detail

BuiltinAggregation

public BuiltinAggregation()
Method Detail

getName

abstract String getName()

create

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


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

implementStartAndNext

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

Specified by:
implementStartAndNext in interface 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

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.


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)

sum

public static int sum(int v)

sum

public static double sum(double v)

min

public static int min(Object v)

min

public static double min(int v)

min

public static double min(double v)

max

public static int max(Object v)

max

public static double max(int v)

max

public static double max(double v)

SourceForge.net_Logo