unionSet (Aggregate Function)
Union multiple sets. This attribute aggregator maintains a union of sets. The given input set is put into the union set and the union set is returned.
Syntax
<OBJECT> unionSet(<OBJECT> set)
Query Parameters
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
set | The java.util.Set object that needs to be added into the union set. | OBJECT | No | Yes |
Example
@info(name = 'query1')
INSERT INTO initStream
SELECT createSet(symbol) AS initialSet
FROM stockStream
@info(name = 'query2')
INSERT INTO distinctStockStream
SELECT unionSet(initialSet) AS distinctSymbols
FROM initStream WINDOW TUMBLING_TIME(10 sec);
These two queries work together to create a set object containing the distinct set of stock symbols received during a tumbling time window of 10 seconds:
The first query, named 'query1', processes records from the
stockStream
and creates an initial set ofsymbol
values using thecreateSet(symbol)
function. The resulting set, namedinitialSet
, is inserted into theinitStream
.The second query, named 'query2', processes records from the
initStream
and applies a tumbling time window of 10 seconds. For each window, theunionSet(initialSet)
function is applied to create a single set containing the union of allinitialSet
values within that window. The resulting set, nameddistinctSymbols
, contains unique stock symbols from the window and is inserted into thedistinctStockStream
.
In summary, distinctStockStream
returns the set object which contains the distinct set of stock symbols received during a tumbling time window of 10 seconds.