Class UserDefinedAggregator
java.lang.Object
org.apache.derby.impl.sql.execute.UserDefinedAggregator
- All Implemented Interfaces:
Externalizable
,Serializable
,Formatable
,TypedFormat
,ExecAggregator
Aggregator for user-defined aggregates. Wraps the application-supplied
implementation of org.apache.derby.agg.Aggregator.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Aggregator
private boolean
private DataTypeDescriptor
private static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
accumulate
(DataValueDescriptor addend, Object ga) Iteratively accumulates the addend into the aggregator.boolean
Return true if the aggregation eliminated at least one null from the input data set.Return the result of the aggregation. .int
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.void
merge
(ExecAggregator addend) Merges one aggregator into a another aggregator.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
private void
setup
(Class<?> udaClass, DataTypeDescriptor resultType) Initialization logic shared by setup() and newAggregator()void
setup
(ClassFactory classFactory, String aggregateName, DataTypeDescriptor resultType) Set's up the aggregate for processing.void
-
Field Details
-
FIRST_VERSION
private static final int FIRST_VERSION- See Also:
-
_aggregator
-
_resultType
-
_eliminatedNulls
private boolean _eliminatedNulls
-
-
Constructor Details
-
UserDefinedAggregator
public UserDefinedAggregator()0-arg constructor for Formatable interface
-
-
Method Details
-
setup
Description copied from interface:ExecAggregator
Set's up the aggregate for processing.- Specified by:
setup
in interfaceExecAggregator
- 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
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 interfaceExecAggregator
-
accumulate
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 interfaceExecAggregator
- Parameters:
addend
- the DataValueDescriptor addend (current input to the aggregation)ga
- a result set getter- Throws:
StandardException
- on error
-
merge
Description copied from interface:ExecAggregator
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(); }
- Specified by:
merge
in interfaceExecAggregator
- Parameters:
addend
- the other Aggregator (input partial aggregate)- Throws:
StandardException
- on error
-
getResult
Return the result of the aggregation. .- Specified by:
getResult
in interfaceExecAggregator
- Returns:
- the aggregated result (could be a Java null).
- Throws:
StandardException
- on error
-
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 interfaceExecAggregator
- Returns:
- ExecAggregator the new aggregator
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
- on error
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
- on errorClassNotFoundException
- See Also:
-
getTypeFormatId
public int getTypeFormatId()Get the formatID which corresponds to this class.- Specified by:
getTypeFormatId
in interfaceTypedFormat
- Returns:
- the formatID of this class
-
logAggregatorInstantiationError
Record an instantiation error trying to load the aggregator class.
-