This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

R Language Extension

First you need to setup the prerequisites .

This extension allows you to execute R scripts within Siddhi query. Following are the functions of the R extension.

Evaluation function

Syntax[<int|long|float|double|string|boolean>  output1 ,  <int|long|float|double|string|boolean>   output2, ... ] r:eval   ( <string > script,  <string >  outputAttributes, <int|long|float|double|string|boolean >  input1 , <int|long|float|double|string|boolean> input2 , ... )
Extension TypeStreamProcessor
DescriptionThis runs the R script for each event and produces  aggregated outputs based on the provided input variable parameters and expected output attributes.
Parameters

script : R script as a string produces aggregated outputs based on the provided input variable parameters and expected output attributes.
outputAttributes  : A set of output attributes separated by commas as string. Each attribute is denoted as <name><space><type>. e.g., 'output1 string, output2 long'

Return ParametersOutput parameters are generated based on the outputAttributes provided.
Example

eval('totalItems <- sum(items); totalTemp <- sum(temp);', 'totalItems int, totalTemp double', items, temp), where the data type of items is int and that of temp is doublereturns [ totalItems, totalTemp ], where the data type of totalItems is int and that of totalTemp is double.

@info(name = 'query1') 
from dataIn#window.lengthBatch(2)#r:eval('totalItems <- sum(items); totalTemp <- sum(temp);', 'totalItems int, totalTemp double', items, temp)
select *
insert into dataOut;

 

Evaluation Source function

Syntax[<int|long|float|double|string|boolean>  output1 ,  <int|long|float|double|string|boolean>   output2, ... ] r:eval   ( <string > filePath,  <string >  outputAttributes,<int|long|float|double|string|boolean>  input1 , <int|long|float|double|string|boolean> input2 , ... )
Extension TypeStream Processor
DescriptionThis runs the R script loaded from a file to each event and produces aggregated outputs based on the provided input variable parameters and expected output attributes.
Parameters

filePath : The file path of the R script where this script uses the input variable parameters and produces the expected output attributes.

outputAttributes  : A set of output attributes separated by commas as string. Each attribute is denoted as <name><space><type>. e.g., 'output1 string, output2 long'

ReturnOutput parameters are generated based on the outputAttributes provided.
Example

evalSource('/home/user/test/script1.R', 'totalItems int, totalTemp double', items, temp), where the data type of items is int and that of temp is double returns [ totalItems, totalTemp ] where the data type of totalTemp is int and that of totalTemp is double.

@info(name = 'query1') 
from dataIn#window.lengthBatch(2)#r:evalSource('/home/user/test/script1.R', 'totalItems int, totalTemp double', items, temp)
select *
insert into dataOut;