Skip to main content

collect (Aggregate Function)

Collect multiple key-value pairs to construct a map. Only distinct keys are collected. If a duplicate key arrives, then it overrides the old value.

Syntax

<OBJECT> map:collect(<INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> key, <OBJECT|INT|LONG|FLOAT|DOUBLE|BOOL|STRING> value)

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
keyKey of the map entryINT LONG FLOAT DOUBLE FLOAT BOOL STRINGNoYes
valueValue of the map entryOBJECT INT LONG FLOAT DOUBLE BOOL STRINGNoYes

Example 1

insert into OutputStream
select map:collect(symbol, price) as stockDetails
from StockStream WINDOW TUMBLING_LENGTH(10);

For the window expiration of 10 events, the collect() function will collect attributes of key and value to a single map and return as stockDetails.