Class CumulativeUtil

java.lang.Object
com.illumon.iris.db.v2.utils.CumulativeUtil

public class CumulativeUtil
extends Object
Utilities for cumulative and rolling aggregations.
  • Constructor Details

  • Method Details

    • accumulate

      public static Table accumulate​(Table t, String key, double startValue, String newCol, String formula)
      General purpose core method for executing running and cumulative aggregations. Used by helper methods which provide template formulae for specific types of aggregations.
      Parameters:
      t - The Table to use as input to the aggregation.
      key - Nullable string key to use to access the cached previous row value within the CumulativeUtil.CumulativeHelper map. Note that a non-null literal key must be enclosed in backticks since it will be used in a formula. Typically a column expression, rather than a literal, is used to allow operations based on the grouping of the expression.
      startValue - Initial value from which to start aggregating. Normally 0.
      newCol - The name of the aggregation column to add to the table.
      formula - A formula indicating how to calculate the aggregation. This is normally provides by a helper method. An example would be something like: "_prev+A" to cumulatively sum A.
      Returns:
      A Table with the new aggregation column added. Note that this column will be a double column, regardless of the numeric type(s) of the formula input(s).
    • cumMin

      public static Table cumMin​(Table t, String newCol, String formula)
      Executes a cumulative aggregation of the minimum value so far for a formula.
      Parameters:
      t - The Table to use as input to the aggregation.
      newCol - The name of the aggregation column to add to the table.
      formula - A formula for the source value on which to calculate a running minimum. This can be as simple as the column name or a more complex expression.
      Returns:
      A Table with the new aggregation column added. Note that this column will be a double column, regardless of the numeric type(s) of the formula input(s).
    • cumSum

      public static Table cumSum​(Table t, String key, String newCol, String formula)
      Executes a cumulative sum aggregation far for a formula.
      Parameters:
      t - The Table to use as input to the aggregation.
      key - Nullable string key to use to access the cached previous row value within the CumulativeUtil.CumulativeHelper map. Note that a non-null literal key must be enclosed in backticks since it will be used in a formula. Typically a column expression, rather than a literal, is used to allow operations based on the grouping of the expression.
      newCol - The name of the aggregation column to add to the table.
      formula - A formula for the source value on which to calculate a running sum. This can be as simple as the column name or a more complex expression.
      Returns:
      A Table with the new aggregation column added. Note that this column will be a double column, regardless of the numeric type(s) of the formula input(s).
    • cumSum

      public static Table cumSum​(Table t, String newCol, String formula)
      Executes a cumulative sum aggregation far for a formula.
      Parameters:
      t - The Table to use as input to the aggregation.
      newCol - The name of the aggregation column to add to the table.
      formula - A formula for the source value on which to calculate a running sum. This can be as simple as the column name or a more complex expression.
      Returns:
      A Table with the new aggregation column added. Note that this column will be a double column, regardless of the numeric type(s) of the formula input(s).
    • rollingSum

      public static Table rollingSum​(Table t, int windowSize, String newCol, String formula)
      Executes a rolling sum aggregation far for a formula.
      Parameters:
      t - The Table to use as input to the aggregation.
      windowSize - The number of rows to include in the rolling sum window.
      newCol - The name of the aggregation column to add to the table.
      formula - A formula for the source value on which to calculate a running sum. This can be as simple as the column name or a more complex expression.
      Returns:
      A Table with the new aggregation column added. Note that this column will be a double column, regardless of the numeric type(s) of the formula input(s).
    • filterChanged

      public static Table filterChanged​(Table t, String key, String col)
      Returns only rows for which the selected column value is different from the value in the previous row.
      Parameters:
      t - The Table to use as input to the method.
      key - Nullable string key to use to access the cached previous row value within the CumulativeUtil.CumulativeHelper map. Note that a non-null literal key must be enclosed in backticks since it will be used in a formula. Typically a column expression, rather than a literal, is used to allow operations based on the grouping of the expression.
      col - The column to check for changing values.
      Returns:
      A Table of only rows where the selected value has changed from the value in the previous row.
    • main

      public static void main​(String... args) throws IOException
      main method to show examples of use of this class' methods.
      Parameters:
      args - Not used
      Throws:
      IOException