limit

The limit operator returns a result array with K number of cells of the input array, beginning with an offset number.

Synopsis

limit(array, count:cells_to_return[, offset:cells_to_skip]);

limit(array, count[, offset]);

The count parameter is required.  The offset parameter defaults to zero.

Summary

The count parameter is required, and the optional offset parameter will default to zero if not specified. Both count and offset parameters may also be specified positionally, with the required count being specified immediately after the array and the offset after the count.

The parameters are uint64 number of cells to return or skip. The output schema is always the same as the input schema. count always returns either that number of cells (minus the offset) or the entire array - whichever is smaller. The cells that are chosen to return are indeterminate, and may vary. Optimized for small values of count. Negative inputs and null inputs are coerced to a limit equal to max signed int64 - effectively returning the entire array.

The cells are returned in the order in which they are stored, which may not be the indexed order.  If deterministic return in is required with regard to the indices, use sort() on those indices to ensure the expected order.

Examples

Using the Operator

To demonstrate limit operator, do the following:

  1. Create an array with random values:

    AFL% store(build(<val:double> [x=1:100,1000000,0], random()), temp)



  2. Return up to K cells from an array.

    AFL% limit(temp, 5);
    AFL% limit(temp, count:5);
  3. The output is:

    {x} val
    {1} 1.01289e+09
    {2} 1.50197e+08
    {3} 1.80527e+09
    {4} 1.43597e+09
    {5} 1.2949e+0
  4. Return up to K cells from an array, starting with the 6th cell.

    AFL% limit(temp, 5, 5);
    AFL% limit(temp, count:5, offset:5);


    The output is:

    {x} val
    {6} 1.54031e+09
    {7} 5.33976e+08
    {8} 1.73624e+09
    {9} 2.66371e+08
    {10} 1.5245e+09
  5. Remove the array:

    AFL% remove(temp);