List Functions
List functions allow you to create and interact with lists.
For information on performing scatter and gather using list:tokenize(), and list:collect(), refer to the examples in Data Pipeline Examples.
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]
]
Example
This example shows how to use basic list functions.
-- Defines `ProductComboStream` having `string` type attributes `product1`, `product2`, and `product3`.
CREATE STREAM ProductComboStream ( product1 string, product2 string, product3 string);
@info(name = 'Create-list')
-- Create a list with values of `product1`, `product2`, and `product3`.
insert into NewListStream
select list:create(product1, product2, product3)
as productList
from ProductComboStream;
@info(name = 'Check-list')
-- Check if `productList` is a List.
insert into ListAnalysisStream
select list:isList(productList) as isList,
-- Check if `productList` contains `'Cake'`.
list:contains(productList, 'Cake')
as isCakePresent,
-- Check if `productList` is empty.
list:isEmpty(productList) as isEmpty,
-- Get the value at index `1` from `productList` .
list:get(productList, 1) as valueAt1,
-- Get size of `productList`.
list:size(productList) as size
from NewListStream;
@info(name = 'Clone-and-update')
-- Clone `productList`, add `Toffee` to the end of the list, and remove `Cake` from the list.
insert into UpdatedListStream
select list:remove(
list:add(list:clone(productList), "Toffee"),
"Cake") as productList
from NewListStream;
📄️ add (Function)
Function returns the updated list after adding the given value.
📄️ addAll (Function)
Function returns the updated list after adding all the values from the given list.
📄️ clear (Function)
Function returns the cleared list.
📄️ clone (Function)
Function returns the cloned list.
📄️ collect (Aggregate Function)
Collects multiple values to construct a list.
📄️ contains (Function)
Function checks whether the list contains the specific value.
📄️ containsAll (Function)
Function checks whether the list contains all the values in the given list.
📄️ create (Function)
Function creates a list containing all values provided.
📄️ get (Function)
Function returns the value at the specific index, null if index is out of range.
📄️ indexOf (Function)
Function returns the last index of the given element.
📄️ isEmpty (Function)
Function checks if the list is empty.
📄️ isList (Function)
Function checks if the object is type of a list.
📄️ lastIndexOf (Function)
Function returns the index of the given value.
📄️ merge (Aggregate Function)
Collects multiple lists to merge as a single list.
📄️ remove (Function)
Function returns the updated list after removing the element with the specified value.
📄️ removeAll (Function)
Function returns the updated list after removing all the element with the specified list.
📄️ removeByIndex (Function)
Function returns the updated list after removing the element with the specified index.
📄️ retainAll (Function)
Function returns the updated list after retaining all the elements in the specified list.
📄️ setValue (Function)
Function returns the updated list after replacing the element in the given index by the given value.
📄️ size (Function)
Function to return the size of the list.
📄️ sort (Function)
Function returns lists sorted in ascending or descending order.
📄️ tokenize (Stream Processor)
Tokenize the list and return each key, value as new attributes in events