nosort

nosort in process definition, contextual keyword

The nosort contextual keyword marks a user-defined process as order-independent. Such a process is called without specifying a sort or scan option.

def nosort process mySquaredSum(x : number) with
  y = sum(x)
  return y^2

table T = extend.range(3)

x = mySquaredSum(T.N)

// 36
show scalar "Squared Sum" a1b1 with x

To ensure order-independence, a nosort process cannot define internal mutable state via the keep keyword. Additionally, a nosort process can only call other nosort proccess, either built-in or user-defined. The intent behind the nosort keyword is to allow more performant execution by explicitly removing the order of the input vectors of the process, when applicable.

The code above can be rewritten without the nosort option as follows:

def process mySquaredSum(x : number) with
  keep y = 0
  y = y + x
  return y^2

table T = extend.range(3)

x = mySquaredSum(T.N) sort 1

// 36
show scalar "Squared Sum" a1b1 with x

Thus, we used keep y = 0 for internal mutable state and sort 1 for an unspecified ordering.

In practice though, the use of the nosort option is expected to be relatively rare in regular Envision code. Its purpose is mostly to mark special functions (called aggregators) as having provably order-independent implementations. Some examples of such Envision aggregators that are defined as built-in nosort processes are sum, avg, min, max, stdev, and stdevp.

See also

User Contributed Notes
0 notes + add a note