|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.derby.impl.sql.execute.SystemAggregator
org.apache.derby.impl.sql.execute.OrderableAggregator
org.apache.derby.impl.sql.execute.SumAggregator
org.apache.derby.impl.sql.execute.AvgAggregator
public final class AvgAggregator
Aggregator for AVG(). Extends the SumAggregator and implements a count. Result is then sum()/count(). To handle overflow we catch the exception for value out of range, then we swap the holder for the current sum to one that can handle a larger range. Eventually a sum may end up in a SQLDecimal which can handle an infinite range. Once this type promotion has happened, it will not revert back to the original type, even if the sum would fit in a lesser type.
| Field Summary | |
|---|---|
private long |
count
|
private int |
scale
|
| Fields inherited from class org.apache.derby.impl.sql.execute.OrderableAggregator |
|---|
value |
| Constructor Summary | |
|---|---|
AvgAggregator()
|
|
| Method Summary | |
|---|---|
protected void |
accumulate(DataValueDescriptor addend)
Accumulate |
DataValueDescriptor |
getResult()
Return the result of the aggregation. |
int |
getTypeFormatId()
Get the formatID which corresponds to this class. |
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 |
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.SumAggregator |
|---|
toString |
| Methods inherited from class org.apache.derby.impl.sql.execute.OrderableAggregator |
|---|
setup |
| Methods inherited from class org.apache.derby.impl.sql.execute.SystemAggregator |
|---|
accumulate, didEliminateNulls |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private long count
private int scale
| Constructor Detail |
|---|
public AvgAggregator()
| Method Detail |
|---|
protected void accumulate(DataValueDescriptor addend)
throws StandardException
SumAggregator
accumulate in class SumAggregatoraddend - value to be added in
StandardException - on errorExecAggregator.accumulate(org.apache.derby.iapi.types.DataValueDescriptor, java.lang.Object)
public void merge(ExecAggregator addend)
throws StandardException
ExecAggregatorAn 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();
}
merge in interface ExecAggregatormerge in class OrderableAggregatoraddend - the other Aggregator
(input partial aggregate)
StandardException - on errorExecAggregator.merge(org.apache.derby.iapi.sql.execute.ExecAggregator)
public DataValueDescriptor getResult()
throws StandardException
getResult in interface ExecAggregatorgetResult in class OrderableAggregatorStandardException - on errorpublic ExecAggregator newAggregator()
ExecAggregator
newAggregator in interface ExecAggregatornewAggregator in class SumAggregator
public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
OrderableAggregatorWhy 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.
writeExternal in interface java.io.ExternalizablewriteExternal in class OrderableAggregatorjava.io.IOException - on errorExternalizable.writeExternal(java.io.ObjectOutput)
public void readExternal(java.io.ObjectInput in)
throws java.io.IOException,
java.lang.ClassNotFoundException
readExternal in interface java.io.ExternalizablereadExternal in class OrderableAggregatorjava.io.IOException - on error
java.lang.ClassNotFoundException - on errorExternalizable.readExternal(java.io.ObjectInput)public int getTypeFormatId()
getTypeFormatId in interface TypedFormatgetTypeFormatId in class SumAggregator
|
Built on Wed 2013-06-12 15:21:56+0000, from revision ??? | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||