Class VarPAggregator<V extends java.lang.Number>
- java.lang.Object
-
- org.apache.derby.impl.sql.execute.VarPAggregator<V>
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,Aggregator<V,java.lang.Double,VarPAggregator<V>>
- Direct Known Subclasses:
StdDevPAggregator
,VarSAggregator
public class VarPAggregator<V extends java.lang.Number> extends java.lang.Object implements Aggregator<V,java.lang.Double,VarPAggregator<V>>, java.io.Externalizable
This class implements the SQL Standard VAR_POP() aggregator, computing a population's variance. It uses the IBM formula described here:
sum(xi2)/n - m2 where n is the number of items in the population m is the population average x1 ... xn are the items in the population
The IBM formula can be computed without buffering up an arbitrarily long list of items. The IBM formula is algebraically equivalent to the textbook formula for population variance:
sum( (xi - m)2 )/n
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VarPAggregator.Sums
-
Field Summary
Fields Modifier and Type Field Description protected int
count
private static long
serialVersionUID
protected VarPAggregator.Sums
sums
-
Constructor Summary
Constructors Constructor Description VarPAggregator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accumulate(V value)
Accumulate the next scalar valueprotected java.lang.Double
computeVar()
void
init()
Initialize the Aggregatorvoid
merge(VarPAggregator<V> otherAggregator)
For merging another partial result into this Aggregator.void
readExternal(java.io.ObjectInput in)
java.lang.Double
terminate()
Return the result scalar valuevoid
writeExternal(java.io.ObjectOutput out)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
sums
protected VarPAggregator.Sums sums
-
count
protected int count
-
-
Method Detail
-
init
public void init()
Description copied from interface:Aggregator
Initialize the Aggregator- Specified by:
init
in interfaceAggregator<V extends java.lang.Number,java.lang.Double,VarPAggregator<V extends java.lang.Number>>
-
accumulate
public void accumulate(V value)
Description copied from interface:Aggregator
Accumulate the next scalar value- Specified by:
accumulate
in interfaceAggregator<V extends java.lang.Number,java.lang.Double,VarPAggregator<V extends java.lang.Number>>
-
merge
public void merge(VarPAggregator<V> otherAggregator)
Description copied from interface:Aggregator
For merging another partial result into this Aggregator. This lets the SQL interpreter divide the incoming rows into subsets, aggregating each subset in isolation, and then merging the partial results together. This method can be called when performing a grouped aggregation with a large number of groups. While processing such a query, Derby may write intermediate grouped results to disk. The intermediate results may be retrieved and merged with later results if Derby encounters later rows which belong to groups whose intermediate results have been written to disk. This situation can occur with a query like the following:
select a, mode( b ) from mode_inputs group by a order by a
- Specified by:
merge
in interfaceAggregator<V extends java.lang.Number,java.lang.Double,VarPAggregator<V extends java.lang.Number>>
-
computeVar
protected java.lang.Double computeVar()
-
terminate
public java.lang.Double terminate()
Description copied from interface:Aggregator
Return the result scalar value- Specified by:
terminate
in interfaceAggregator<V extends java.lang.Number,java.lang.Double,VarPAggregator<V extends java.lang.Number>>
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
-