Skip to main content

SORT()

This window holds a batch of events that equal the number specified as the window length and sorts them in the given order.

Syntax

WINDOW SORT(<INT> length, <STRING|DOUBLE|INT|LONG|FLOAT|LONG> attribute)
WINDOW SORT(<INT> length, <STRING|DOUBLE|INT|LONG|FLOAT|LONG> attribute, <STRING> order, <STRING> ...)
WINDOW SORT(<INT> length, <STRING|DOUBLE|INT|LONG|FLOAT|LONG> attribute, <STRING> order, <STRING|DOUBLE|INT|LONG|FLOAT|LONG> attribute, <STRING|DOUBLE|INT|LONG|FLOAT|LONG> ...)

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
lengthThe size of the window length.INTNoNo
attributeThe attribute that should be checked for the order.The concatenation of all the attributes of the event is considered.STRING DOUBLE INT LONG FLOAT LONGNoYes
orderThe order define as "asc" or "desc".ascSTRINGYesNo

Example

CREATE STREAM cseEventStream (symbol string, price float, volume long);
CREATE WINDOW cseEventWindow (symbol string, price float, volume long) SORT(2,volume, 'asc');
CREATE SINK STREAM OutputStream (volume long);

@info(name = 'query0')
INSERT INTO cseEventWindow
FROM cseEventStream;

@info(name = 'query1')
INSERT all events INTO OutputStream
SELECT volume
FROM cseEventWindow;

SORT(5, price, asc) keeps the events sorted by price in the ascending order. At any given time, the window contains the five lowest prices.