genericTStateIterate#

swordfish.function.genericTStateIterate()#

This function performs calculation with time-based windows iteratively.

Suppose T is a time column, X is [X1, X2, …, Xn], column “factor” in the output table holds the calculation results, column “initial” is the initial column, window is set to “w”, and the iterate function is “func”.

For the k-th record (with its timestamp Tk), the calculation rule is:

  • Tk ∈ [T1, T1+w): factor[k] = initial[k]

  • factor[k] = func(subFactor, X1[k], X2[k], … , Xn[k]), where

    • subFactor is the value of factor in the current window

    • the window for the (k+1)th record is (Tk-w, Tk] (when leftClosed=false) or [Tk-w, Tk] (when leftClosed=true).

Parameters:
  • T (Constant) – A non-strictly increasing vector of temporal or integral type. It cannot contain null values. Note that out-of-order data is discarded in the calculation.

  • X (Constant) – Can be column(s) from the input table, or the calculation results by applying a vector function to the column(s). You can set X to [] to leave it unspecified; or use a tuple to specify multiple columns for X.

  • initial (Constant) – The column used to fill the initial window in the result column of the output table. It can be a column from the input table, or the calculation results by applying a vector function to it. Suppose the timestamp of the first record is t0, the initial window is [t0, t0 + window), measured by time interval.

  • window (Constant) – A positive integer or a DURATION scalar that specifies the window size. When window is an integer, it has the same time unit as T.

  • func (Constant) –

    A stateless user-defined function with one scalar as the return value. Arguments passed to func are as follows:

    • The first argument is a vector containing the previous window results.

    • Then followed by columns specified in X.

    • [Optional] Other fixed constants to be passed to func. In this case, you can fix the arguments with partial application.

  • leftClosed (Constant, optional) – A Boolean value indicating whether the left boundary of the window is inclusive. The default value is false.