Package com.illumon.iris.db.v2.utils
Class CumulativeUtil
java.lang.Object
com.illumon.iris.db.v2.utils.CumulativeUtil
Utilities for cumulative and rolling aggregations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProvides a helper class with a map to cache previous row values when performing filtering of data whose values change from row to row.static classProvides a helper class with a map to cache previous row values when performing rolling or cumulative aggregations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Tableaccumulate(Table t, String key, double startValue, String newCol, String formula) General purpose core method for executing running and cumulative aggregations.static TableExecutes a cumulative aggregation of the minimum value so far for a formula.static TableExecutes a cumulative sum aggregation far for a formula.static TableExecutes a cumulative sum aggregation far for a formula.static TablefilterChanged(Table t, String key, String col) Returns only rows for which the selected column value is different from the value in the previous row.static voidmain method to show examples of use of this class' methods.static TablerollingSum(Table t, int windowSize, String newCol, String formula) Executes a rolling sum aggregation far for a formula.
-
Constructor Details
-
CumulativeUtil
public CumulativeUtil()
-
-
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- TheTableto use as input to the aggregation.key- Nullable string key to use to access the cached previous row value within theCumulativeUtil.CumulativeHelpermap. 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
Tablewith 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
Executes a cumulative aggregation of the minimum value so far for a formula.- Parameters:
t- TheTableto 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
Tablewith 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
Executes a cumulative sum aggregation far for a formula.- Parameters:
t- TheTableto use as input to the aggregation.key- Nullable string key to use to access the cached previous row value within theCumulativeUtil.CumulativeHelpermap. 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
Tablewith 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
Executes a cumulative sum aggregation far for a formula.- Parameters:
t- TheTableto 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
Tablewith 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
Executes a rolling sum aggregation far for a formula.- Parameters:
t- TheTableto 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
Tablewith 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
Returns only rows for which the selected column value is different from the value in the previous row.- Parameters:
t- TheTableto use as input to the method.key- Nullable string key to use to access the cached previous row value within theCumulativeUtil.CumulativeHelpermap. 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
Tableof only rows where the selected value has changed from the value in the previous row.
-
main
main method to show examples of use of this class' methods.- Parameters:
args- Not used- Throws:
IOException
-