Class SumAvgAggregate

All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
Avg, AvgDistinct, Sum, SumDistinct

public class SumAvgAggregate extends AggregateFunction
This aggregate function can be used to compute both SUM and AVERAGE functions. It computes both the sum and average of a collection of values.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    This value is set to true if we want to compute the average value.
    private int
    The current count of items that have been added
    private boolean
    Indicates whether we want distinct values or not
    (package private) HashSet<Object>
    Set to keep track of distinct values
    private Object
    Contains the actual value of the sum
  • Constructor Summary

    Constructors
    Constructor
    Description
    SumAvgAggregate(boolean computeAverage, boolean distinct)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a value to the aggregate function so that it can update its internal state.
    void
    Clears the aggregate function's current state so that the object can be reused to compute an aggregate on another set of input values.
    Returns the aggregated result computed for this aggregate function.
    Returns the column type of the resulting column after applying the function.

    Methods inherited from class edu.caltech.nanodb.functions.AggregateFunction

    supportsDistinct

    Methods inherited from class edu.caltech.nanodb.functions.Function

    clone

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • computeAverage

      private boolean computeAverage
      This value is set to true if we want to compute the average value. Otherwise, we compute the sum.
    • sum

      private Object sum
      Contains the actual value of the sum
    • count

      private int count
      The current count of items that have been added
    • distinct

      private boolean distinct
      Indicates whether we want distinct values or not
    • set

      Set to keep track of distinct values
  • Constructor Details

    • SumAvgAggregate

      public SumAvgAggregate(boolean computeAverage, boolean distinct)
  • Method Details

    • clearResult

      public void clearResult()
      Description copied from class: AggregateFunction
      Clears the aggregate function's current state so that the object can be reused to compute an aggregate on another set of input values.
      Specified by:
      clearResult in class AggregateFunction
    • addValue

      public void addValue(Object value)
      Description copied from class: AggregateFunction
      Adds a value to the aggregate function so that it can update its internal state. Generally, aggregate functions ignore null inputs (which represent SQL NULL values) when computing their results.
      Specified by:
      addValue in class AggregateFunction
      Parameters:
      value - the value to add to the aggregate function
    • getResult

      public Object getResult()
      Description copied from class: AggregateFunction
      Returns the aggregated result computed for this aggregate function. Generally, if aggregate functions receive no non-null inputs then they should produce a null result. (COUNT is an exception to this rule, producing 0 in that case.)
      Specified by:
      getResult in class AggregateFunction
      Returns:
      the result of the aggregate computation.
    • getReturnType

      public ColumnType getReturnType(List<Expression> args, Schema schema)
      Description copied from class: ScalarFunction
      Returns the column type of the resulting column after applying the function. This generally depends on the column type of the inputs.
      Specified by:
      getReturnType in class ScalarFunction
      Parameters:
      args - the arguments to the function call
      schema - the schema of the table
      Returns:
      the column type of the resulting column