Top Description Methods
org.apache.derby.iapi.sql.execute

public Interface ExecAggregator

extends Formatable
Known Direct Implementers
org.apache.derby.impl.sql.execute.SystemAggregator, org.apache.derby.impl.sql.execute.UserDefinedAggregator
Imports
org.apache.derby.iapi.types.DataTypeDescriptor, .DataValueDescriptor, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.io.Formatable, org.apache.derby.iapi.services.loader.ClassFactory

An ExecAggregator is the interface that execution uses to an aggregate. System defined aggregates will implement this directly.

The life time of an ExecAggregator is as follows.

  1. An ExecAggregator instance is created using the defined class name.
  2. Its setup() method is called to define its role (COUNT(*), SUM, etc.).
  3. Its newAggregator() method may be called any number of times to create new working aggregators as required. These aggregators have the same role and must be created in an initialized state.
  4. accumlate and merge will be called across these set of aggregators
  5. One of these aggregators will be used as the final one for obtaining the result

Method Summary

Modifier and TypeMethod and Description
public void
accumulate(DataValueDescriptor
the DataValueDescriptor addend (current input to the aggregation)
addend
,
Object
a result set getter
ga
)

Iteratively accumulates the addend into the aggregator.

public boolean
didEliminateNulls()

Return true if the aggregation eliminated at least one null from the input data set.

public DataValueDescriptor
getResult()

Produces the result to be returned by the query.

public void
merge(ExecAggregator
the other Aggregator (input partial aggregate)
inputAggregator
)

Merges one aggregator into a another aggregator.

public ExecAggregator

Returns:

ExecAggregator the new aggregator
newAggregator
()

Return a new initialized copy of this aggregator, any state set by the setup() method of the original Aggregator must be copied into the new aggregator.

public void
setup(ClassFactory
Database-specific class factory.
classFactory
,
String
For builtin aggregates, this is a SQL aggregate name like MAX. For user-defined aggregates, this is the name of the user-written class which implements org.apache.derby.agg.Aggregator.
aggregateName
,
DataTypeDescriptor
The type returned by the getResult() method.
returnDataType
)

Set's up the aggregate for processing.

Method Detail

accumulateback to summary
public void accumulate(DataValueDescriptor addend, Object ga) throws StandardException

Iteratively accumulates the addend into the aggregator. Called on each member of the set of values that is being aggregated.

Parameters
addend:DataValueDescriptor

the DataValueDescriptor addend (current input to the aggregation)

ga:Object

a result set getter

Exceptions
StandardException:
on error
didEliminateNullsback to summary
public boolean didEliminateNulls()

Return true if the aggregation eliminated at least one null from the input data set.

getResultback to summary
public DataValueDescriptor getResult() throws StandardException

Produces the result to be returned by the query. The last processing of the aggregate.

Exceptions
StandardException:
on error
mergeback to summary
public void merge(ExecAggregator inputAggregator) throws StandardException

Merges one aggregator into a another aggregator. Merges two partial aggregates results into a single result. Needed for:

  • parallel aggregation
  • vector aggregation (GROUP BY)
  • distinct aggregates (e.g. MAX(DISTINCT Col))

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(ExecAggregator inputAggregator) throws StandardException
		{
		   count += ((CountAccgregator)inputAggregator).getCount();
		} 
Parameters
inputAggregator:ExecAggregator

the other Aggregator (input partial aggregate)

Exceptions
StandardException:
on error
newAggregatorback to summary
public ExecAggregator newAggregator()

Return a new initialized copy of this aggregator, any state set by the setup() method of the original Aggregator must be copied into the new aggregator.

Returns:ExecAggregator

ExecAggregator the new aggregator

setupback to summary
public void setup(ClassFactory classFactory, String aggregateName, DataTypeDescriptor returnDataType)

Set's up the aggregate for processing.

Parameters
classFactory:ClassFactory

Database-specific class factory.

aggregateName:String

For builtin aggregates, this is a SQL aggregate name like MAX. For user-defined aggregates, this is the name of the user-written class which implements org.apache.derby.agg.Aggregator.

returnDataType:DataTypeDescriptor

The type returned by the getResult() method.