Skip to main content
Version: Java (Groovy)

RollingSum

RollingSum calculates a window-based rolling sum for an updateBy table operation. The rolling sum can be calculated using forward and/or backward windows.

Syntax

RollingSum(revTicks, fwdTicks, pairs...)
RollingSum(revTicks, pairs...)
RollingSum(timestampCol, revTime, fwdTime, pairs...)
RollingSum(timestampCol, revTime, pairs...)
RollingSum(timestampCol, revDuration, fwdDuration, pairs...)
RollingSum(timestampCol, revDuration, pairs...)

Parameters

ParameterTypeDescription
revTickslong

The look-behind window size in ticks (rows).

fwdTickslong

The look-forward window size in ticks (rows).

pairsString...

The input/output column name pairs.

timestampColString

The name of the DateTime column.

revTimelong

The look-behind window size in nanoseconds.

fwdTimelong

The look-forward window size in nanoseconds.

revDurationDuration

The look-behind window size in Duration.

fwdDurationDuration

The look-forward window size in Duration.

Returns

An UpdateByOperation to be used in an updateBy table operation.

Examples

The following example performs an updateBy on the source table using three row-based RollingSum operations. Each operation gives varying revTicks and fwdTicks values to show how they affect the output. The windows for each operation are as follows:

  • opBefore: The window contains two rows. It starts two rows before the current row, and ends at the row before the current row.
  • opAfter: The window contains three rows. It starts one row after the current row, and ends three rows after the current row.
  • opMiddle: The window contains three rows. It starts one row before the current row, and ends one row ahead of the current row.
source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = i")

opPrior = RollingSum(3, -1, "WindowPriorX = X")
opPosterior = RollingSum(-1, 3, "WindowPosteriorX = X")
opMiddle = RollingSum(2, 1, "WindowMiddleX = X")

result = source.updateBy([opPrior, opPosterior, opMiddle], "Letter")

The following example performs an updateBy on the source table using three time-based RollingSum operations. Each operation gives varying revTime and fwdTime values to show how they affect the output. The windows for each operation are as follows:

  • opBefore: The window starts five seconds before the current row, and ends one second before the current row.
  • opAfter: The window starts one second after the current row, and ends five seconds after the current row.
  • opMiddle: The window starts three seconds before the current row, and ends three seconds after the current row.
baseTime = parseInstant("2023-01-01T00:00:00 ET")

source = emptyTable(10).update("Timestamp = baseTime + i * SECOND", "Letter = (i % 2 == 0) ? `A` : `B`", "X = i")

opBefore = RollingSum("Timestamp", 5 * SECOND, -1 * SECOND, "WindowBeforeX = X")
opAfter = RollingSum("Timestamp", -1 * SECOND, 5 * SECOND, "WindowAfterX = X")
opMiddle = RollingSum("Timestamp", 3 * SECOND, 3 * SECOND, "WindowMiddleX = X")

result = source.updateBy([opBefore, opAfter, opMiddle], "Letter")