Class VarPAggregator<V extends java.lang.Number>

  • 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  
    • 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 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VarPAggregator

        public VarPAggregator()
    • Method Detail

      • init

        public void init()
        Description copied from interface: Aggregator
        Initialize the Aggregator
        Specified by:
        init in interface Aggregator<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 interface Aggregator<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 interface Aggregator<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 interface Aggregator<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 interface java.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 interface java.io.Externalizable
        Throws:
        java.io.IOException