Class CountAggregator
- java.lang.Object
-
- org.apache.derby.impl.sql.execute.SystemAggregator
-
- org.apache.derby.impl.sql.execute.CountAggregator
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,Formatable
,TypedFormat
,ExecAggregator
public final class CountAggregator extends SystemAggregator
Aggregator for COUNT()/COUNT(*).- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
isCountStar
private long
value
-
Constructor Summary
Constructors Constructor Description CountAggregator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
accumulate(DataValueDescriptor addend)
void
accumulate(DataValueDescriptor addend, java.lang.Object ga)
Accumulate for count().DataValueDescriptor
getResult()
Return the result of the aggregation.int
getTypeFormatId()
Get the formatID which corresponds to this class.boolean
isCountStar()
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)
void
setup(ClassFactory cf, java.lang.String aggregateName, DataTypeDescriptor returnType)
Set's up the aggregate for processing.void
writeExternal(java.io.ObjectOutput out)
Although we are not expected to be persistent per se, we may be written out by the sorter temporarily.-
Methods inherited from class org.apache.derby.impl.sql.execute.SystemAggregator
didEliminateNulls, toString
-
-
-
-
Method Detail
-
setup
public void setup(ClassFactory cf, java.lang.String aggregateName, DataTypeDescriptor returnType)
Description copied from interface:ExecAggregator
Set'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.returnType
- The type returned by the getResult() method.
-
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:- 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()
Return the result of the aggregation. Just spit out the running count.- Returns:
- the value as a Long
-
accumulate
public void accumulate(DataValueDescriptor addend, java.lang.Object ga) throws StandardException
Accumulate for count(). Toss out all nulls in this kind of count. Increment the count for count(*). Count even the null values.- Specified by:
accumulate
in interfaceExecAggregator
- Overrides:
accumulate
in classSystemAggregator
- Parameters:
addend
- value to be added inga
- the generic aggregator that is calling me- Throws:
StandardException
- on error- See Also:
ExecAggregator.accumulate(org.apache.derby.iapi.types.DataValueDescriptor, java.lang.Object)
-
accumulate
protected final void accumulate(DataValueDescriptor addend)
- Specified by:
accumulate
in classSystemAggregator
-
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.- Returns:
- ExecAggregator the new aggregator
-
isCountStar
public boolean isCountStar()
-
writeExternal
public final void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
Although 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.- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Overrides:
writeExternal
in classSystemAggregator
- Throws:
java.io.IOException
- thrown on error
-
readExternal
public final void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Overrides:
readExternal
in classSystemAggregator
- Throws:
java.io.IOException
- io exceptionjava.lang.ClassNotFoundException
- on error- See Also:
Externalizable.readExternal(java.io.ObjectInput)
-
getTypeFormatId
public int getTypeFormatId()
Get the formatID which corresponds to this class.- Returns:
- the formatID of this class
-
-