List

Provides examples on basic list functions provided via siddhi-execution-list extension.

For information of performing scatter and gather using list:tokenize(), and list:collect() refer the examples in Data Pipelining section. For information on all list functions, refer the Siddhi APIs.

define stream ProductComboStream (
            product1 string, product2 string, product3 string);

@info(name = 'Create-list')
from ProductComboStream
select list:create(product1, product2, product3)
            as productList
insert into NewListStream;

@info(name = 'Check-list')
from NewListStream
select list:isList(productList) as isList,
       list:contains(productList, 'Cake')
            as isCakePresent,
       list:isEmpty(productList) as isEmpty,
       list:get(productList, 1) as valueAt1,
       list:size(productList) as size
insert into ListAnalysisStream;

@info(name = 'Clone-and-update')
from NewListStream
select list:remove(
            list:add(list:clone(productList), "Toffee"),
            "Cake") as productList
insert into UpdatedListStream;
define stream ProductComboStream (
            product1 string, product2 string, product3 string);

Defines ProductComboStream having string type attributes product1, product2, and product3.

@info(name = 'Create-list')
from ProductComboStream
select list:create(product1, product2, product3)
            as productList

Create a list with values of product1, product2, and product3.

insert into NewListStream;
@info(name = 'Check-list')
from NewListStream
select list:isList(productList) as isList,

Check if productList is a List.

       list:contains(productList, 'Cake')
            as isCakePresent,

Check if productList contains 'Cake'.

       list:isEmpty(productList) as isEmpty,

Check if productList is empty.

       list:get(productList, 1) as valueAt1,

Get the value at index 1 from productList .

       list:size(productList) as size

Get size of productList.

insert into ListAnalysisStream;
@info(name = 'Clone-and-update')
from NewListStream
select list:remove(
            list:add(list:clone(productList), "Toffee"),
            "Cake") as productList

Clone productList, add Toffee to the end of the list, and remove Cake from the list.

insert into UpdatedListStream;

Input

Below event is sent to ProductComboStream,

['Ice Cream', 'Chocolate', 'Cake']

Output

After processing, the following events will be arriving at each stream:

  • NewListStream:
    [[Ice Cream, Chocolate, Cake]]
  • ListAnalysisStream:
    [true, true, false, Chocolate, 3]
  • UpdatedListStream:
    [[Ice Cream, Chocolate, Toffee]]
Top