Map
Provides examples on basic map functions provided via siddhi-execution-map extension.
For information of performing scatter and gather using map:tokenize()
, and map:collect()
refer the examples in Data Pipelining section. For information on all map functions, refer the Siddhi APIs.
define stream CoupleDealInfoStream (
item1 string, price1 double,
item2 string, price2 double);
@info(name = 'Create-map')
from CoupleDealInfoStream
select map:create(item1, price1, item2, price2)
as itemPriceMap
insert into NewMapStream;
@info(name = 'Check-map')
from NewMapStream
select map:isMap(itemPriceMap) as isMap,
map:containsKey(itemPriceMap, 'Cookie')
as isCookiePresent,
map:containsValue(itemPriceMap, 24.0)
as isThereItemWithPrice24,
map:isEmpty(itemPriceMap) as isEmpty,
map:keys(itemPriceMap) as keys,
map:size(itemPriceMap) as size
insert into MapAnalysisStream;
@info(name = 'Clone-and-update')
from NewMapStream
select map:replace(
map:put(map:clone(itemPriceMap),
"Gift",
1.0),
"Cake",
12.0) as itemPriceMap
insert into ItemInsertedMapStream;
|
Defines |
|
|
|
Create a map with values of |
|
|
|
|
|
Check if |
|
Check if |
|
Check if |
|
Check if |
|
Get all keys of |
|
Get size of |
|
|
|
|
|
Clone |
|
Input
Below event is sent to CoupleDealInfoStream
,
['Chocolate'
, 18.0
, 'Ice Cream'
, 24.0
]
Output
After processing, the following events will be arriving at each stream:
- NewMapStream:
[{Ice Cream=24.0, Chocolate =18.0}
] - MapAnalysisStream:
[true
,false
,true
,false
,[Ice Cream, Chocolate]
,2
] - ItemInsertedMapStream:
[{Ice Cream=24.0, Gift=1.0, Chocolate =18.0}
]