Top Description Fields Constructors Methods
org.apache.derby.impl.sql.execute

public final Class UserDefinedAggregator

extends Object
implements ExecAggregator
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.execute.ExecAggregator, org.apache.derby.iapi.services.io.Formatable, org.apache.derby.iapi.services.io.TypedFormat, java.io.Externalizable, java.io.Serializable
Imports
java.io.ObjectOutput, .ObjectInput, .IOException, java.sql.SQLException, org.apache.derby.agg.Aggregator, org.apache.derby.iapi.services.monitor.Monitor, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.sql.execute.ExecAggregator, org.apache.derby.iapi.types.DataTypeDescriptor, .DataValueDescriptor, .TypeId, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.iapi.services.io.StoredFormatIds, org.apache.derby.iapi.services.loader.ClassFactory, org.apache.derby.shared.common.reference.MessageId, .SQLState

Aggregator for user-defined aggregates. Wraps the application-supplied implementation of org.apache.derby.agg.Aggregator.

Field Summary

Modifier and TypeField and Description
private Aggregator<V, R, A extends Aggregator<V, R, A>>
private boolean
private DataTypeDescriptor
private static final int

Constructor Summary

AccessConstructor and Description
public
UserDefinedAggregator()

0-arg constructor for Formatable interface

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
)

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.accumulate.

Iteratively accumulates the addend into the aggregator.

public boolean
didEliminateNulls()

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.didEliminateNulls.

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

public DataValueDescriptor

Returns:

the aggregated result (could be a Java null).
getResult
()

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.getResult.

Return the result of the aggregation.

public int

Returns:

the formatID of this class
getTypeFormatId
()

Implements org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

Get the formatID which corresponds to this class.

private void
logAggregatorInstantiationError(String aggregateName, Throwable t)

Record an instantiation error trying to load the aggregator class.

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

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.merge.

Merges one aggregator into a another aggregator.

public ExecAggregator
newAggregator()

Implements org.apache.derby.iapi.sql.execute.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.

public void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

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.
resultType
)

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.setup.

Set's up the aggregate for processing.

private void
setup(Class<?> udaClass, DataTypeDescriptor resultType)

Initialization logic shared by setup() and newAggregator()

public void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_aggregatorback to summary
private Aggregator<V, R, A extends Aggregator<V, R, A>> _aggregator
_eliminatedNullsback to summary
private boolean _eliminatedNulls
_resultTypeback to summary
private DataTypeDescriptor _resultType
FIRST_VERSIONback to summary
private static final int FIRST_VERSION

Constructor Detail

UserDefinedAggregatorback to summary
public UserDefinedAggregator()

0-arg constructor for Formatable interface

Method Detail

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

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.accumulate.

Doc from org.apache.derby.iapi.sql.execute.ExecAggregator.accumulate.

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

Annotations
@SuppressWarnings:unchecked
Exceptions
StandardException:
on error
didEliminateNullsback to summary
public boolean didEliminateNulls()

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.didEliminateNulls.

Doc from org.apache.derby.iapi.sql.execute.ExecAggregator.didEliminateNulls.

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

getResultback to summary
public DataValueDescriptor getResult() throws StandardException

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.getResult.

Return the result of the aggregation. .

Returns:DataValueDescriptor

the aggregated result (could be a Java null).

Exceptions
StandardException:

Doc from org.apache.derby.iapi.sql.execute.ExecAggregator.getResult.

on error

getTypeFormatIdback to summary
public int getTypeFormatId()

Implements org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

Get the formatID which corresponds to this class.

Returns:int

the formatID of this class

logAggregatorInstantiationErrorback to summary
private void logAggregatorInstantiationError(String aggregateName, Throwable t)

Record an instantiation error trying to load the aggregator class.

mergeback to summary
public void merge(ExecAggregator addend) throws StandardException

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.merge.

Doc from org.apache.derby.iapi.sql.execute.ExecAggregator.merge.

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
addend:ExecAggregator

the other Aggregator (input partial aggregate)

Annotations
@SuppressWarnings:unchecked
Exceptions
StandardException:
on error
newAggregatorback to summary
public ExecAggregator newAggregator()

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.newAggregator.

Doc from org.apache.derby.iapi.sql.execute.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

readExternalback to summary
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Implements java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Parameters
in:ObjectInput

the stream to read data from in order to restore the object

Exceptions
IOException:
on error
ClassNotFoundException:
If the class for an object being restored cannot be found.
See Also
java.io.Externalizable#readExternal
setupback to summary
public void setup(ClassFactory classFactory, String aggregateName, DataTypeDescriptor resultType)

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.setup.

Doc from org.apache.derby.iapi.sql.execute.ExecAggregator.setup.

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.

resultType:DataTypeDescriptor

The type returned by the getResult() method.

setupback to summary
private void setup(Class<?> udaClass, DataTypeDescriptor resultType)

Initialization logic shared by setup() and newAggregator()

writeExternalback to summary
public void writeExternal(ObjectOutput out) throws IOException

Implements java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Parameters
out:ObjectOutput

the stream to write the object to

Exceptions
IOException:
on error