sort

sort, process option

The sort option orders a process call and returns only the final value.

Examples

table T = with
  [| as N, as L |]
  [| 1, "b" |]
  [| 0, "a" |]
  [| 2, "c" |]

def process myConcat(t: text) with
  keep txt = ""
  txt = "\{txt}\{t}"
  return txt

x = myConcat(T.L) sort T.N
y = myConcat(T.L) sort -T.N

show summary "Sorted" with
  x
  y

This outputs the following summary:

x y
abc cba

sort auto uses the primary dimension ordering of the input table instead of an explicit ordering expression:

table T = with
  [| as Group, as Value |]
  [| "A", 5 |]
  [| "A", 2 |]
  [| "B", 9 |]
  [| "B", 7 |]

table G[g] = by T.Group
G.FirstValue = first(T.Value) by T.Group at g sort auto

show table "First values" with
  g as "Group"
  G.FirstValue

This outputs the first value encountered in each group:

Group FirstValue
A 5
B 9

Remarks

sort behaves like scan but only keeps the final value. sort auto follows the primary dimension ordering, so changing that dimension can change the result. With an explicit ordering expression, the order of ties is unspecified.

See also

User Contributed Notes
0 notes + add a note