Top Description Fields Constructors Methods
org.apache.derby.impl.sql.execute

public final Class CountAggregator

extends SystemAggregator
Class Inheritance
Imports
org.apache.derby.iapi.types.DataTypeDescriptor, .DataValueDescriptor, org.apache.derby.iapi.services.loader.ClassFactory, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.sql.execute.ExecAggregator, org.apache.derby.iapi.services.io.StoredFormatIds, .Formatable, java.io.ObjectOutput, .ObjectInput, .IOException

Aggregator for COUNT()/COUNT(*).

Field Summary

Modifier and TypeField and Description
private boolean
private long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
accumulate(DataValueDescriptor
value to be added in
addend
,
Object
the generic aggregator that is calling me
ga
)

Overrides org.apache.derby.impl.sql.execute.SystemAggregator.accumulate.

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.accumulate.

Accumulate for count().

protected final void
public DataValueDescriptor

Returns:

the value as a Long
getResult
()

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.getResult.

Return the result of the aggregation.

public int

Returns:

the formatID of this class
getTypeFormatId
()

Implements org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

Get the formatID which corresponds to this class.

public boolean
public void
merge(ExecAggregator
the other Aggregator (input partial aggregate)
addend
)

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.merge.

Merges one aggregator into a another aggregator.

public ExecAggregator

Returns:

ExecAggregator the new aggregator
newAggregator
()

Implements org.apache.derby.iapi.sql.execute.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.

public final void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Overrides org.apache.derby.impl.sql.execute.SystemAggregator.readExternal.

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

public void
setup(ClassFactory
Database-specific class factory.
cf
,
String
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.
aggregateName
,
DataTypeDescriptor
The type returned by the getResult() method.
returnType
)

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.setup.

Set's up the aggregate for processing.

public final void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Overrides org.apache.derby.impl.sql.execute.SystemAggregator.writeExternal.

Implements java.io.Externalizable.writeExternal.

Although we are not expected to be persistent per se, we may be written out by the sorter temporarily.

Inherited from org.apache.derby.impl.sql.execute.SystemAggregator:
didEliminateNullstoString

Field Detail

isCountStarback to summary
private boolean isCountStar
valueback to summary
private long value

Constructor Detail

CountAggregatorback to summary
public CountAggregator()

Method Detail

accumulateback to summary
public void accumulate(DataValueDescriptor addend, Object ga) throws StandardException

Overrides org.apache.derby.impl.sql.execute.SystemAggregator.accumulate.

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.accumulate.

Accumulate for count(). Toss out all nulls in this kind of count. Increment the count for count(*). Count even the null values.

Parameters
addend:DataValueDescriptor

value to be added in

ga:Object

the generic aggregator that is calling me

Exceptions
StandardException:

Doc from org.apache.derby.iapi.sql.execute.ExecAggregator.accumulate.

on error

See Also
ExecAggregator#accumulate
accumulateback to summary
protected final void accumulate(DataValueDescriptor addend)

Implements abstract org.apache.derby.impl.sql.execute.SystemAggregator.accumulate.

getResultback to summary
public DataValueDescriptor getResult()

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.getResult.

Return the result of the aggregation. Just spit out the running count.

Returns:DataValueDescriptor

the value as a Long

getTypeFormatIdback to summary
public int getTypeFormatId()

Implements org.apache.derby.iapi.services.io.TypedFormat.getTypeFormatId.

Get the formatID which corresponds to this class.

Returns:int

the formatID of this class

isCountStarback to summary
public boolean isCountStar()
mergeback to summary
public void merge(ExecAggregator addend) throws StandardException

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.merge.

Doc from org.apache.derby.iapi.sql.execute.ExecAggregator.merge.

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:ExecAggregator

the other Aggregator (input partial aggregate)

Exceptions
StandardException:
on error
See Also
ExecAggregator#merge
newAggregatorback to summary
public ExecAggregator newAggregator()

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.newAggregator.

Doc from org.apache.derby.iapi.sql.execute.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.

Returns:ExecAggregator

ExecAggregator the new aggregator

readExternalback to summary
public final void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Overrides org.apache.derby.impl.sql.execute.SystemAggregator.readExternal.

Implements java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Parameters
in:ObjectInput

the stream to read data from in order to restore the object

Exceptions
IOException:
io exception
ClassNotFoundException:
on error
See Also
java.io.Externalizable#readExternal
setupback to summary
public void setup(ClassFactory cf, String aggregateName, DataTypeDescriptor returnType)

Implements org.apache.derby.iapi.sql.execute.ExecAggregator.setup.

Doc from org.apache.derby.iapi.sql.execute.ExecAggregator.setup.

Set's up the aggregate for processing.

Parameters
cf:ClassFactory

Database-specific class factory.

aggregateName:String

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:DataTypeDescriptor

The type returned by the getResult() method.

writeExternalback to summary
public final void writeExternal(ObjectOutput out) throws IOException

Overrides org.apache.derby.impl.sql.execute.SystemAggregator.writeExternal.

Implements java.io.Externalizable.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.

Parameters
out:ObjectOutput

Doc from java.io.Externalizable.writeExternal.

the stream to write the object to

Exceptions
IOException:
thrown on error