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