This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Reorder Extension

Reorder extension is implemented using the K-Slack algorithm. The K-Slack Siddhi extension is used for reordering events from an unordered event stream. The following is an example of a query with the reorder extension.

 

@info(name = 'query1') 
from inputStream#reorder:kslack(eventTimestamp) 
select eventTimestamp, price, volume 
insert into outputStream;

There are several important variations of the K-slack API of which the details are described below

K-Slack function

Syntax

<bool> reorder:kslack(<long> timestamp)

Extension TypeStreamProcessor
DescriptionThis is the most basic version. The events are sorted by the  timestamp  parameter.
Syntax

<bool> reorder:kslack(<long> timestamp, <long> timeOut )

Extension TypeStreamProcessor
DescriptionThe second argument shown in the above syntax corresponds to a fixed time-out value set at the beginning of the process. Once the time-out value expires, the extension drains all the events that are buffered within the reorder extension to outside. The time out has been implemented internally using a timer. The events buffered within the extension are released each time the timer ticks.
Syntax
<bool> reorder:kslack(<long> timestamp, <long> timeOut, <long> maxValue )
Extension TypeStreamProcessor
DescriptionThe third argument in the above syntax is the maximum value for K. This is the amount to which the K value of the K-Slack algorithm will be increased.
Example
  • kslack(timestamp, -1l, 1000000)
    In the above example, the algorithm execution starts when K=0 and it gets increased up to 1000000. The value of the K-slack does not increase from that point onwards. Hence, this leads to lower latency compared to the version shown in the first (i.e., single parameter) example of this list. Note that the second argument is set to -1l which effectively disables the timer based draining of the internal buffer.
  • kslack(timestamp, 1000l, 1000000)
    The above is another variation of the third category. Here, a time-out value is specified for the second argument (i.e. 1000 ms). In this case, the K-slack algorithm buffers events until the 1000ms time period expires. The maximum K value is 1000000. The K-value cannot exceed the specified amount.

Syntax

<bool>  reorder:kslack (<long> timestamp, <long> timeOut, <bool> expireFlag )

Extension TypeStreamProcessor
DescriptionThe fourth argument in the above syntax is a flag that indicates whether the out-of order events that appear after the expiration of the K-slack window should be discarded or not.
Examplekslack(timestamp, -1l, true)