Class Aggregation

java.lang.Object
com.pervasive.datarush.operators.group.Aggregation

public final class Aggregation extends Object
A representation of an aggregation on a specific field in a record. To be used with Group.

Users should only use the #Aggregation(AggregatorFactory, String) constructor for custom-coded aggregation operators. Otherwise, they should use the static factory methods this class provides, such as #sum(String) and #max(String).

  • Constructor Details

    • Aggregation

      public Aggregation(AggregatorFactory aggregatorFactory, String sourceField)
      Constructs an Aggregation for a specified record field using specified arguments.
      Parameters:
      aggregatorFactory - the factory for constructing the desired aggregator
      sourceField - the field to aggregate
    • Aggregation

      public Aggregation(AggregatorFactory aggregatorFactory, ScalarValuedFunction sourceFunction)
      Constructs an Aggregation for a specified record field using specified arguments.
      Parameters:
      aggregatorFactory - the factory for constructing the desired aggregator
      sourceFunction - the function to aggregate
    • Aggregation

      public Aggregation(AggregatorFactory aggregatorFactory, List<ScalarValuedFunction> sourceFunctions)
      Constructs an Aggregation for a specified record field using specified arguments.
      Parameters:
      aggregatorFactory - the factory for constructing the desired aggregator
      sourceFields - the fields to aggregate
  • Method Details

    • as

      public Aggregation as(String label)
      Creates an identical aggregation whose output field name will be the specified label. This is analogous to the AS keyword in SQL. The supplied name must be unique among all fields in the result or an error will be raised during graph composition.

      Use this method to explictly specify the name of the result. For example, to sum the prices in the group and label the result "revenue":

      Aggegation.sum("salePrice").as("revenue")

      Parameters:
      label - the name to use for the output field
      Returns:
      an aggregation using the specified name for the result field
    • distinct

      public Aggregation distinct(boolean distinct)
      Creates an identical aggregation whose distinct flag is set to the specified value.
      Parameters:
      distinct - whether to compute distinct aggregations
      Returns:
      an aggregation whose distinct flag is set accordinging
    • isDistinct

      public boolean isDistinct()
      Returns whether to compute the aggregation based on the distinct values of the given field(s).
      Returns:
      whether to compute the aggregation based on the distinct values of the given field(s).
    • getSourceFunctions

      public List<ScalarValuedFunction> getSourceFunctions()
      Returns the source functions of this aggregation.
      Returns:
      the source functions of this aggregation.
    • getAggregatorFactory

      public AggregatorFactory getAggregatorFactory()
      Returns the aggregator factory for this aggregation.
      Returns:
      the aggregator factory for this aggregation.
    • getOutputName

      public String getOutputName()
      Returns the output name for this aggregation.
      Returns:
      the output name for this aggregation.
    • validateInputType

      public void validateInputType(RecordTokenType inputType)
      Validate the input types to this aggregation.
      Parameters:
      inputType - the type of the record used as input to the aggregation
      Throws:
      DRException - if a subexpression evaluates to a type incompatible with the aggregation or parent function, or if a referenced field is not present in the input type
    • avg

      public static Aggregation avg(String input)
      Create an average value aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      average value aggregation
    • avg

      public static Aggregation avg(ScalarValuedFunction input)
      Create an average value aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      average value aggregation
    • count

      public static Aggregation count()
      Create a count aggregation for all rows within a group. Equivalent to the SQL count(*).
      Returns:
      a count aggregation for all rows within a group.
    • count

      public static Aggregation count(String input)
      Create a value count aggregation for the given input. This aggregation only counts non-null values.
      Parameters:
      input - input field name
      Returns:
      non-null value count aggregation
    • count

      public static Aggregation count(ScalarValuedFunction input)
      Create a value count aggregation for the given input. This aggregation only counts non-null values.
      Parameters:
      input - input function
      Returns:
      non-null value count aggregation
    • corr

      public static Aggregation corr(String input1, String input2)
      Create a correlation aggregation for the given inputs.
      Parameters:
      input1 - input field name
      input2 - input field name
      Returns:
      correlation aggregation
    • corr

      public static Aggregation corr(ScalarValuedFunction input1, ScalarValuedFunction input2)
      Create a correlation aggregation for the given inputs.
      Parameters:
      input1 - input function
      input2 - input function
      Returns:
      correlation aggregation
    • covar

      public static Aggregation covar(String input1, String input2)
      Create a covariance aggregation for the given inputs.
      Parameters:
      input1 - input field name
      input2 - input field name
      Returns:
      covariance (population) aggregation
    • covar

      public static Aggregation covar(String input1, String input2, boolean sample)
      Create a covariance aggregation for the given inputs.
      Parameters:
      input1 - input field name
      input2 - input field name
      sample - whether to adjust for sampling
      Returns:
      covariance aggregation
    • covar

      public static Aggregation covar(ScalarValuedFunction input1, ScalarValuedFunction input2)
      Create a covariance aggregation for the given inputs.
      Parameters:
      input1 - input function
      input2 - input function
      Returns:
      covariance (population) aggregation
    • covar

      public static Aggregation covar(ScalarValuedFunction input1, ScalarValuedFunction input2, boolean sample)
      Create a covariance aggregation for the given inputs.
      Parameters:
      input1 - input function
      input2 - input function
      sample - whether to adjust for sampling
      Returns:
      covariance aggregation
    • geoAvg

      public static Aggregation geoAvg(String input)
      Create a geometric average value aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      geometric average value aggregation
    • geoAvg

      public static Aggregation geoAvg(ScalarValuedFunction input)
      Create a geometric average value aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      geometric average value aggregation
    • harmAvg

      public static Aggregation harmAvg(String input)
      Create an harmonic average value aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      harmonic average value aggregation
    • harmAvg

      public static Aggregation harmAvg(ScalarValuedFunction input)
      Create an harmonic average value aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      harmonic average value aggregation
    • kurtosis

      public static Aggregation kurtosis(String input)
      Create a kurtosis aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      kurtosis (population) aggregation
    • kurtosis

      public static Aggregation kurtosis(String input, boolean sample)
      Create a kurtosis aggregation for the given input.
      Parameters:
      input - input field name
      sample - whether to adjust for sampling
      Returns:
      kurtosis aggregation
    • kurtosis

      public static Aggregation kurtosis(ScalarValuedFunction input)
      Create a kurtosis aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      kurtosis (population) aggregation
    • kurtosis

      public static Aggregation kurtosis(ScalarValuedFunction input, boolean sample)
      Create a kurtosis aggregation for the given input.
      Parameters:
      input - input function
      sample - whether to adjust for sampling
      Returns:
      kurtosis aggregation
    • max

      public static Aggregation max(String input)
      Create a maximum value aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      maximum value aggregation
    • max

      public static Aggregation max(ScalarValuedFunction input)
      Create a maximum value aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      maximum value aggregation
    • min

      public static Aggregation min(String input)
      Create a minimum value aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      minimum value aggregation
    • min

      public static Aggregation min(ScalarValuedFunction input)
      Create a minimum value aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      minimum value aggregation
    • moment

      public static Aggregation moment(String input, int k)
      Create a central moment aggregation for the given input.
      Parameters:
      input - input field name
      k - the moment to calculate.
      Returns:
      central moment aggregation
    • moment

      public static Aggregation moment(ScalarValuedFunction input, int k)
      Create a central moment aggregation for the given input.
      Parameters:
      input - input field name
      k - the moment to calculate.
      Returns:
      central moment aggregation
    • skewness

      public static Aggregation skewness(String input)
      Create a skewness aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      skewness (population) aggregation
    • skewness

      public static Aggregation skewness(String input, boolean sample)
      Create a skewness aggregation for the given input.
      Parameters:
      input - input field name
      sample - whether to adjust for sampling
      Returns:
      skewness aggregation
    • skewness

      public static Aggregation skewness(ScalarValuedFunction input)
      Create a skewness aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      skewness (population) aggregation
    • skewness

      public static Aggregation skewness(ScalarValuedFunction input, boolean sample)
      Create a skewness aggregation for the given input.
      Parameters:
      input - input function
      sample - whether to adjust for sampling
      Returns:
      skewness aggregation
    • stddev

      public static Aggregation stddev(String input)
      Create a standard deviation aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      standard deviation (population) aggregation
    • stddev

      public static Aggregation stddev(String input, boolean sample)
      Create a standard deviation aggregation for the given input.
      Parameters:
      input - input field name
      sample - whether to adjust for sampling
      Returns:
      standard deviation aggregation
    • stddev

      public static Aggregation stddev(ScalarValuedFunction input)
      Create a standard deviation aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      standard deviation (population) aggregation
    • stddev

      public static Aggregation stddev(ScalarValuedFunction input, boolean sample)
      Create a standard deviation aggregation for the given input.
      Parameters:
      input - input function
      sample - whether to adjust for sampling
      Returns:
      standard deviation aggregation
    • sum

      public static Aggregation sum(String input)
      Create a value summation aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      summation aggregation type
    • sum

      public static Aggregation sum(ScalarValuedFunction input)
      Create a value summation aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      summation aggregation type
    • sumSquares

      public static Aggregation sumSquares(String input)
      Create a sum-squares aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      summation aggregation type
    • sumSquares

      public static Aggregation sumSquares(ScalarValuedFunction input)
      Create a sum-squares aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      summation aggregation type
    • var

      public static Aggregation var(String input)
      Create a variance aggregation for the given input.
      Parameters:
      input - input field name
      Returns:
      variance (population) aggregation
    • var

      public static Aggregation var(String input, boolean sample)
      Create a variance aggregation for the given input.
      Parameters:
      input - input field name
      sample - whether to adjust for sampling
      Returns:
      variance (sample) aggregation
    • var

      public static Aggregation var(ScalarValuedFunction input)
      Create a variance aggregation for the given input.
      Parameters:
      input - input function
      Returns:
      variance (population) aggregation
    • var

      public static Aggregation var(ScalarValuedFunction input, boolean sample)
      Create a variance aggregation for the given input.
      Parameters:
      input - input function
      sample - whether to adjust for sampling
      Returns:
      variance (sample) aggregation
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object