variable_window

The variable_window operator calculates aggregate values over nonempty cells from a variable size, 1-dimensional window.

Synopsis

variable_window(array, dimension, number_of_preceding_cells, number_of_trailing_cells, aggregate1(attr_name1)[,aggrgegate2(attr_name2)[, ...]])

Summary

The variable_window operator aggregates along a 1-dimensional window of variable length in cells, but constant length counted in non-empty cells.  It does not generate an output where the input cell is empty.

Inputs

The variable_window operator takes the following arguments:

  • array:  A source array with one or more attributes and one or more dimensions.
  • dimension: The dimension along which the window extends.
  • number_of_preceding_cells: The number of cells prior to the current cell to include in the window.
  • number_of_trailing_cells: The number of cells after the current cell to include in the window.
  • aggregateN(attr_name): One or more aggregate functions, to be applied to the specified attribute, attr_name,

Example

To aggregate pairs of numbers along the rows of the array, while ignoring empty cells, do the following:

  1. Create a 2x4 array M and fill it with increasing integers, with an empty cell in the '6' position:

    AFL% create array M <val:double>[i=0:1; j=0:3];
    AFL% store(build(M, '[[0,1,2,3],[4,5,(),7]]', true), M); 


    The output is:

    {i,j} val
    {0,0} 0
    {0,1} 1
    {0,2} 2
    {0,3} 3
    {1,0} 4
    {1,1} 5
    {1,3} 7
  2. Sum pairs of numbers along the rows, with the window preceding the reference cell by 1 and trailing none:

    AFL% variable_window(M, j, 1,0, sum(val)); 


    The output is:

    {i,j} val_sum
    {0,0} 0
    {0,1} 1
    {0,2} 3
    {0,3} 5
    {1,0} 4
    {1,1} 9
    {1,3} 12