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

public Class VarPAggregator<V extends Number>

extends Object
implements Aggregator<V extends Number, Double, VarPAggregator<V extends Number>>, Externalizable
Class Inheritance
All Implemented Interfaces
java.io.Externalizable, java.io.Serializable, org.apache.derby.agg.Aggregator
Known Direct Subclasses
org.apache.derby.impl.sql.execute.VarSAggregator, org.apache.derby.impl.sql.execute.StdDevPAggregator
Imports
java.io.Externalizable, .IOException, .ObjectInput, .ObjectOutput, org.apache.derby.agg.Aggregator

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
protected int
private static final long
protected VarPAggregator.Sums

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
accumulate(V
The new value to accumulate.
value
)

Implements org.apache.derby.agg.Aggregator.accumulate.

Accumulate the next scalar value

protected Double
public void
init()

Implements org.apache.derby.agg.Aggregator.init.

Initialize the Aggregator

public void
merge(VarPAggregator<V>
The other Aggregator to merge with
otherAggregator
)

Implements org.apache.derby.agg.Aggregator.merge.

For merging another partial result into this Aggregator.

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

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 Double
terminate()

Implements org.apache.derby.agg.Aggregator.terminate.

Return the result scalar value

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

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
protected int count
serialVersionUIDback to summary
private static final long serialVersionUID
sumsback to summary
protected VarPAggregator.Sums sums

Constructor Detail

VarPAggregatorback to summary
public VarPAggregator()

Method Detail

accumulateback to summary
public void accumulate(V value)

Implements org.apache.derby.agg.Aggregator.accumulate.

Doc from org.apache.derby.agg.Aggregator.accumulate.

Accumulate the next scalar value

Parameters
value:V

The new value to accumulate.

Annotations
@Override
computeVarback to summary
protected Double computeVar()
initback to summary
public void init()

Implements org.apache.derby.agg.Aggregator.init.

Doc from org.apache.derby.agg.Aggregator.init.

Initialize the Aggregator

Annotations
@Override
mergeback to summary
public void merge(VarPAggregator<V> otherAggregator)

Implements org.apache.derby.agg.Aggregator.merge.

Doc from org.apache.derby.agg.Aggregator.merge.

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
Parameters
otherAggregator:VarPAggregator<V>

The other Aggregator to merge with

Annotations
@Override
readExternalback to summary
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

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

Annotations
@Override
Exceptions
IOException:
if I/O errors occur
ClassNotFoundException:
If the class for an object being restored cannot be found.
terminateback to summary
public Double terminate()

Implements org.apache.derby.agg.Aggregator.terminate.

Doc from org.apache.derby.agg.Aggregator.terminate.

Return the result scalar value

Returns:Double

the result scalar value

Annotations
@Override
writeExternalback to summary
public void writeExternal(ObjectOutput out) throws IOException

Implements java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Parameters
out:ObjectOutput

the stream to write the object to

Annotations
@Override
Exceptions
IOException:
Includes any I/O exceptions that may occur
org.apache.derby.impl.sql.execute back to summary

public Class VarPAggregator.Sums

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv double
x

pack-priv double

Constructor Summary

AccessConstructor and Description
public
Sums()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

xback to summary
pack-priv double x
x2back to summary
pack-priv double x2

Constructor Detail

Sumsback to summary
public Sums()