An example that demonstrates how to sort rows in a stream.
The stream OrdersIn has rows associated with purchase orders coming in random order, unsorted by StepID. After the rows are processed by the queries in this example, they are published to stream OrdersOut sorted by StepID.
A Window NextStep is used to remember the next StepID for which the query is looking for, for every order. An incoming row triggers a new row if its StepID is equal to NextStep.StepID for this order. This, in turn, can trigger the next row, the row after that, and so on.
A KEEP ALL window is used to enable the processing of early step IDs that arrive late in the query's execution. In a real-world application, a KEEP ALL window would probably be impractical (it would use up too many resources). In such an application the window definition would have a time or row limit, for example: KEEP 1000 ROWS.