org.apache.derby.impl.sql.execute
Class SumAggregator
- java.lang.Object
-
- org.apache.derby.impl.sql.execute.SumAggregator
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable, Formatable, TypedFormat, ExecAggregator
- Direct Known Subclasses:
- AvgAggregator
public class SumAggregator extends java.lang.ObjectAggregator for SUM(). Defers most of its work to OrderableAggregator.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SumAggregator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaccumulate(DataValueDescriptor addend, java.lang.Object ga)Iteratively accumulates the addend into the aggregator.booleandidEliminateNulls()Return true if the aggregation eliminated at least one null from the input data set.DataValueDescriptorgetResult()Return the result of the operations that we have been performing.intgetTypeFormatId()Get the formatID which corresponds to this class.voidmerge(ExecAggregator addend)Merges one aggregator into a another aggregator.ExecAggregatornewAggregator()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.voidreadExternal(java.io.ObjectInput in)voidsetup(ClassFactory cf, java.lang.String aggregateName, DataTypeDescriptor returnDataType)Set's up the aggregate for processing.java.lang.StringtoString()voidwriteExternal(java.io.ObjectOutput out)Although we are not expected to be persistent per se, we may be written out by the sorter temporarily.
-
-
-
Method Detail
-
newAggregator
public ExecAggregator newAggregator()
Description copied from interface:ExecAggregatorReturn 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 the new aggregator
-
getTypeFormatId
public int getTypeFormatId()
Get the formatID which corresponds to this class.- Returns:
- the formatID of this class
-
toString
public java.lang.String toString()
-
setup
public void setup(ClassFactory cf, java.lang.String aggregateName, DataTypeDescriptor returnDataType)
Description copied from interface:ExecAggregatorSet's up the aggregate for processing.- Parameters:
cf- 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.returnDataType- The type returned by the getResult() method.
-
merge
public void merge(ExecAggregator addend) throws StandardException
Description copied from interface:ExecAggregatorMerges 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- the other Aggregator (input partial aggregate)- Throws:
StandardException- on error- See Also:
ExecAggregator.merge(org.apache.derby.iapi.sql.execute.ExecAggregator)
-
getResult
public DataValueDescriptor getResult() throws StandardException
Return the result of the operations that we have been performing. Returns a DataValueDescriptor.- Returns:
- the result as a DataValueDescriptor
- Throws:
StandardException- on error
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionAlthough we are not expected to be persistent per se, we may be written out by the sorter temporarily. So we need to be able to write ourselves out and read ourselves back in. We rely on formatable to handle situations where value is null.Why would we be called to write ourselves out if we are null? For scalar aggregates, we don't bother setting up the aggregator since we only need a single row. So for a scalar aggregate that needs to go to disk, the aggregator might be null.
- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException- on error- See Also:
Externalizable.writeExternal(java.io.ObjectOutput)
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException- on errorjava.lang.ClassNotFoundException- on error- See Also:
Externalizable.readExternal(java.io.ObjectInput)
-
didEliminateNulls
public boolean didEliminateNulls()
Description copied from interface:ExecAggregatorReturn true if the aggregation eliminated at least one null from the input data set.- Specified by:
didEliminateNullsin interfaceExecAggregator
-
accumulate
public void accumulate(DataValueDescriptor addend, java.lang.Object ga) throws StandardException
Description copied from interface:ExecAggregatorIteratively accumulates the addend into the aggregator. Called on each member of the set of values that is being aggregated.- Specified by:
accumulatein interfaceExecAggregator- Parameters:
addend- the DataValueDescriptor addend (current input to the aggregation)ga- a result set getter- Throws:
StandardException- on error
-
-
DataMelt 3.0 © DataMelt by jWork.ORG