Skip to content

API Docs - v2.1.2

Tested Siddhi Core version: 5.1.21

It could also support other Siddhi Core minor versions.

Sinkmapper

csv (Sink Mapper)

This output mapper extension allows you to convert Siddhi events processed by the WSO2 SP to CSV message before publishing them. You can either use custom placeholder to map a custom CSV message or use pre-defined CSV format where event conversion takes place without extra configurations.

Syntax

@sink(..., @map(type="csv", delimiter="<STRING>", header="<BOOL>", event.grouping.enabled="<BOOL>")

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
delimiter

This parameter used to separate the output CSV data, when converting a Siddhi event to CSV format,

, STRING Yes No
header

This parameter specifies whether the CSV messages will be generated with header or not. If this parameter is set to true, message will be generated with header

false BOOL Yes No
event.grouping.enabled

If this parameter is set to true, events are grouped via a line.separator when multiple events are received. It is required to specify a value for the System.lineSeparator() when the value for this parameter is true.

false BOOL Yes No

Examples EXAMPLE 1

@sink(type='inMemory', topic='{{symbol}}', @map(type='csv'))
define stream BarStream (symbol string, price float, volume long);

Above configuration will perform a default CSV output mapping, which will generate output as follows:
 WSO2,55.6,100<OS supported line separator>If header is true and delimiter is "-", then the output will be as follows:
symbol-price-volume<OS supported line separator>WSO2-55.6-100<OS supported line separator>

EXAMPLE 2

@sink(type='inMemory', topic='{{symbol}}', @map(type='csv',header='true',delimiter='-',@payload(symbol='0',price='2',volume='1')))define stream BarStream (symbol string, price float,volume long); 

Above configuration will perform a custom CSV mapping. Here, user can add custom place order in the @payload. The place order indicates that where the attribute name's value will be appear in the output message, The output will be produced output as follows:
WSO2,100,55.6
If header is true and delimiter is "-", then the output will be as follows:
symbol-price-volume
WSO2-55.6-100<OS supported line separator>If event grouping is enabled, then the output is as follows:
WSO2-55.6-100<OS supported line separator>
WSO2-55.6-100<OS supported line separator>
WSO2-55.6-100<OS supported line separator>

Sourcemapper

csv (Source Mapper)

This extension is used to convert CSV message to Siddhi event input mapper. You can either receive pre-defined CSV message where event conversion takes place without extra configurations,or receive custom CSV message where a custom place order to map from custom CSV message.

Syntax

@source(..., @map(type="csv", delimiter="<STRING>", header.present="<BOOL>", fail.on.unknown.attribute="<BOOL>", event.grouping.enabled="<BOOL>")

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
delimiter

When converting a CSV format message to Siddhi event, this parameter indicatesinput CSV message's data should be split by this parameter

, STRING Yes No
header.present

When converting a CSV format message to Siddhi event, this parameter indicates whether CSV message has header or not. This can either have value true or false.If it's set to false then it indicates that CSV message has't header.

false BOOL Yes No
fail.on.unknown.attribute

This parameter specifies how unknown attributes should be handled. If it's set to true and one or more attributes don't havevalues, then SP will drop that message. If this parameter is set to false, the Stream Processor adds the required attribute's values to such events with a null value and the event is converted to a Siddhi event.

true BOOL Yes No
event.grouping.enabled

This parameter specifies whether event grouping is enabled or not. To receive a group of events together and generate multiple events, this parameter must be set to true.

false BOOL Yes No

Examples EXAMPLE 1

@source(type='inMemory', topic='stock', @map(type='csv'))
 define stream FooStream (symbol string, price float, volume int); 

Above configuration will do a default CSV input mapping. Expected input will look like below:
 WSO2 ,55.6 , 100OR
 "WSO2,No10,Palam Groove Rd,Col-03" ,55.6 , 100If header.present is true and delimiter is "-", then the input is as follows:
symbol-price-volumeWSO2-55.6-100

EXAMPLE 2

@source(type='inMemory', topic='stock', @map(type='csv',header='true', @attributes(symbol = "2", price = "0", volume = "1")))
define stream FooStream (symbol string, price float, volume long); 

Above configuration will perform a custom CSV mapping. Here, user can add place order of each attribute in the @attribute. The place order indicates where the attribute name's value has appeared in the input.Expected input will look like below:
55.6,100,WSO2
OR55.6,100,"WSO2,No10,Palm Groove Rd,Col-03"
If header is true and delimiter is "-", then the output is as follows:
price-volume-symbol
55.6-100-WSO2
If group events is enabled then input should be as follows:
price-volume-symbol
55.6-100-WSO2System.lineSeparator()
55.6-100-IBMSystem.lineSeparator()
55.6-100-IFSSystem.lineSeparator()