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
Modifier and Type | Class and Description |
---|---|
static class |
VarPAggregator.Sums |
Modifier and Type | Field and Description |
---|---|
protected int |
count |
private static long |
serialVersionUID |
protected VarPAggregator.Sums |
sums |
Constructor and Description |
---|
VarPAggregator() |
Modifier and Type | Method and Description |
---|---|
void |
accumulate(V value)
Accumulate the next scalar value
|
protected java.lang.Double |
computeVar() |
void |
init()
Initialize the Aggregator
|
void |
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 value
|
void |
writeExternal(java.io.ObjectOutput out) |
private static final long serialVersionUID
protected VarPAggregator.Sums sums
protected int count
public void init()
Aggregator
init
in interface Aggregator<V extends java.lang.Number,java.lang.Double,VarPAggregator<V extends java.lang.Number>>
public void accumulate(V value)
Aggregator
accumulate
in interface Aggregator<V extends java.lang.Number,java.lang.Double,VarPAggregator<V extends java.lang.Number>>
public void merge(VarPAggregator<V> otherAggregator)
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
merge
in interface Aggregator<V extends java.lang.Number,java.lang.Double,VarPAggregator<V extends java.lang.Number>>
protected java.lang.Double computeVar()
public java.lang.Double terminate()
Aggregator
terminate
in interface Aggregator<V extends java.lang.Number,java.lang.Double,VarPAggregator<V extends java.lang.Number>>
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.