Package com.illumon.iris.db.v2.utils
Class CumulativeUtil
java.lang.Object
com.illumon.iris.db.v2.utils.CumulativeUtil
public class CumulativeUtil extends Object
Utilities for cumulative and rolling aggregations.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CumulativeUtil.CumulativeFilterHelper
Provides a helper class with a map to cache previous row values when performing filtering of data whose values change from row to row.static class
CumulativeUtil.CumulativeHelper
Provides a helper class with a map to cache previous row values when performing rolling or cumulative aggregations. -
Constructor Summary
Constructors Constructor Description CumulativeUtil()
-
Method Summary
Modifier and Type Method Description static Table
accumulate(Table t, String key, double startValue, String newCol, String formula)
General purpose core method for executing running and cumulative aggregations.static Table
cumMin(Table t, String newCol, String formula)
Executes a cumulative aggregation of the minimum value so far for a formula.static Table
cumSum(Table t, String newCol, String formula)
Executes a cumulative sum aggregation far for a formula.static Table
cumSum(Table t, String key, String newCol, String formula)
Executes a cumulative sum aggregation far for a formula.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.static void
main(String... args)
main method to show examples of use of this class' methods.static Table
rollingSum(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
- TheTable
to use as input to the aggregation.key
- Nullable string key to use to access the cached previous row value within theCumulativeUtil.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
Executes a cumulative aggregation of the minimum value so far for a formula.- Parameters:
t
- TheTable
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
Executes a cumulative sum aggregation far for a formula.- Parameters:
t
- TheTable
to use as input to the aggregation.key
- Nullable string key to use to access the cached previous row value within theCumulativeUtil.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
Executes a cumulative sum aggregation far for a formula.- Parameters:
t
- TheTable
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
Executes a rolling sum aggregation far for a formula.- Parameters:
t
- TheTable
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
Returns only rows for which the selected column value is different from the value in the previous row.- Parameters:
t
- TheTable
to use as input to the method.key
- Nullable string key to use to access the cached previous row value within theCumulativeUtil.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
main method to show examples of use of this class' methods.- Parameters:
args
- Not used- Throws:
IOException
-