org.apache.derby.impl.sql.execute
Class UserDefinedAggregator

java.lang.Object
  extended by org.apache.derby.impl.sql.execute.UserDefinedAggregator
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, Formatable, TypedFormat, ExecAggregator

public final class UserDefinedAggregator
extends java.lang.Object
implements ExecAggregator

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

See Also:
Serialized Form

Field Summary
private  Aggregator _aggregator
           
private  boolean _eliminatedNulls
           
private  DataTypeDescriptor _resultType
           
private static int FIRST_VERSION
           
 
Constructor Summary
UserDefinedAggregator()
          0-arg constructor for Formatable interface
 
Method Summary
 void accumulate(DataValueDescriptor addend, java.lang.Object ga)
          Iteratively accumulates the addend into the aggregator.
 boolean didEliminateNulls()
          Return true if the aggregation eliminated at least one null from the input data set.
 DataValueDescriptor getResult()
          Return the result of the aggregation. .
 int getTypeFormatId()
          Get the formatID which corresponds to this class.
private  void logAggregatorInstantiationError(java.lang.String aggregateName, java.lang.Throwable t)
          Record an instantiation error trying to load the aggregator class.
 void merge(ExecAggregator addend)
          Merges one aggregator into a another aggregator.
 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.
 void readExternal(java.io.ObjectInput in)
           
private  void setup(java.lang.Class udaClass, DataTypeDescriptor resultType)
          Initialization logic shared by setup() and newAggregator()
 void setup(ClassFactory classFactory, java.lang.String aggregateName, DataTypeDescriptor resultType)
          Set's up the aggregate for processing.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIRST_VERSION

private static final int FIRST_VERSION
See Also:
Constant Field Values

_aggregator

private Aggregator _aggregator

_resultType

private DataTypeDescriptor _resultType

_eliminatedNulls

private boolean _eliminatedNulls
Constructor Detail

UserDefinedAggregator

public UserDefinedAggregator()
0-arg constructor for Formatable interface

Method Detail

setup

public void setup(ClassFactory classFactory,
                  java.lang.String aggregateName,
                  DataTypeDescriptor resultType)
Description copied from interface: ExecAggregator
Set's up the aggregate for processing.

Specified by:
setup in interface ExecAggregator
Parameters:
classFactory - Database-specific class factory.
aggregateName - 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 - The type returned by the getResult() method.

setup

private void setup(java.lang.Class udaClass,
                   DataTypeDescriptor resultType)
Initialization logic shared by setup() and newAggregator()


didEliminateNulls

public boolean didEliminateNulls()
Description copied from interface: ExecAggregator
Return true if the aggregation eliminated at least one null from the input data set.

Specified by:
didEliminateNulls in interface ExecAggregator

accumulate

public void accumulate(DataValueDescriptor addend,
                       java.lang.Object ga)
                throws StandardException
Description copied from interface: ExecAggregator
Iteratively accumulates the addend into the aggregator. Called on each member of the set of values that is being aggregated.

Specified by:
accumulate in interface ExecAggregator
Parameters:
addend - the DataValueDescriptor addend (current input to the aggregation)
ga - a result set getter
Throws:
StandardException - on error

merge

public void merge(ExecAggregator addend)
           throws StandardException
Description copied from interface: ExecAggregator
Merges one aggregator into a another aggregator. 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(ExecAggregator inputAggregator) throws StandardException
                {
                   count += ((CountAccgregator)inputAggregator).getCount();
                } 

Specified by:
merge in interface ExecAggregator
Parameters:
addend - the other Aggregator (input partial aggregate)
Throws:
StandardException - on error

getResult

public DataValueDescriptor getResult()
                              throws StandardException
Return the result of the aggregation. .

Specified by:
getResult in interface ExecAggregator
Returns:
the aggregated result (could be a Java null).
Throws:
StandardException - on error

newAggregator

public ExecAggregator newAggregator()
Description copied from interface: ExecAggregator
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.

Specified by:
newAggregator in interface ExecAggregator
Returns:
ExecAggregator the new aggregator

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException - on error

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException - on error
java.lang.ClassNotFoundException
See Also:
Externalizable.readExternal(java.io.ObjectInput)

getTypeFormatId

public int getTypeFormatId()
Get the formatID which corresponds to this class.

Specified by:
getTypeFormatId in interface TypedFormat
Returns:
the formatID of this class

logAggregatorInstantiationError

private void logAggregatorInstantiationError(java.lang.String aggregateName,
                                             java.lang.Throwable t)
Record an instantiation error trying to load the aggregator class.


Built on Wed 2013-06-12 15:21:56+0000, from revision ???

Apache Derby V10.10 Internals - Copyright © 2004,2013 The Apache Software Foundation. All Rights Reserved.