WSO2 Complex Event Processor is succeeded by WSO2 Stream Processor. To view the latest documentation for WSO2 SP, see WSO2 Stream Processor Documentation.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

Table of Contents

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.

Code Block
@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.

Code Block
@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;