Class Hierarchy    Previous  Next  Index

Interface COM.cloudscape.aggregates.Aggregator


public interface Aggregator
extends java.io.Serializable
Copyright © 1998-2000, Informix Software, Inc. All rights reserved.

Aggregators are user defined set/column functions that are invoked to generate a scalar from a set of values. The Aggregator is used at execution time (AggregateDefinition is used at compile time).

Aggregators provide the methods used to perform aggregation, as well as to store any temporary data used in aggregation. For example, a MAX() aggregator both implements the methods in this interface and stores the temporary result that will be returned by the Aggregator.getResult() method.

Aggregators live for the duration of the aggregation. If an aggregate requires a sort that is large enough, an aggregator may be written to disk while the sort is being processed. Therefore, an aggregator must implement Serializable at a minimum (Externalizable is preferable). An aggregator is never permanently stored on disk.

Aggregators may take any datatype that can be stored in Cloudscape, including serialized Objects. Aggregators may return any type of Object. The input type and the return type must be the same for the duration of a single aggregation. For example,

cannot return both java.lang.Integer and java.lang.String.

NOTE: An Aggregator must implement a zero argument public constructor.

Cloudscape reserves the right to change, rename, or remove this interface at any time.

See Also:
java.io.Serializable, java.io.Externalizable, AggregateDefinition

Method Index

 o accumulate(ResultSet)
Iteratively accumulates the addend into the aggregator.
 o getResult()
Produces the result to be returned by the query.
 o initialize()
Initializes the aggregate for processing.
 o merge(Aggregator)
Merges two partial aggregates results into a single result.
 o newInstance()
Return a new instance of this class.

Method Detail

 o initialize
public void initialize()
          Initializes the aggregate for processing.
 o accumulate
public void accumulate(java.sql.ResultSet addend) throws java.lang.Throwable
          Iteratively accumulates the addend into the aggregator. Called on each member of the set of values that is being aggregated. For example, for SUM on {1,2,3}, the aggregator which is used to implement SUM will be called accumulate 1, 2, and 3.
Parameters:
addend - The addend (current input to the aggregation) in a one row, one column java.sql.ResultSet wrapper. NOTE: next() has already been called on this result set (i.e. it is already positioned on the only row), so all you need to do to retrieve a value is to call getXXX(1).
Throws:
java.lang.Throwable - on error
 o merge
public void merge(Aggregator inputAggregator) throws java.lang.Throwable
          Merges two partial aggregates results into a single result. Needed for:

An example of a merge would be: given two COUNT() aggregators, C1 and C2, a merge of C1 into C2 would set C1.count += C2.count. So, given a CountAggregator with a getCount() method that returns its counts, its merge method might look like this:


public void merge(Aggregator inputAggregator) throws StandardException
{
   count += ((CountAccgregator)inputAggregator).getCount();
} 
Parameters:
inputAggregator - the other Aggregator (input partial aggregate)
Throws:
java.lang.Throwable - on error
 o getResult
public java.lang.Object getResult()
          Produces the result to be returned by the query. The last processing of the aggregate.
Returns:
the resultant value
See Also:
AggregateDefinition
 o newInstance
public Aggregator newInstance()
          Return a new instance of this class. Identical to Class.newInstance() but much cheaper because reflection is costly.

Just implement it to do new myClass().

Returns:
Aggregator

  Class Hierarchy    Previous  Next  Index