Skip to content

API Docs - v4.0.15

R

eval (Stream Processor)

The R Script Stream Processor runs the R script defined within the Siddhi application to each event and produces aggregated outputs based on the input variable parameters provided and the expected output attributes.

Syntax

r:eval(<STRING> script, <INT|LONG|FLOAT|DOUBLE|STRING|STRING> output.attributes, <INT|LONG|FLOAT|DOUBLE|STRING|STRING> input.attributes)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
script The R script as a string which produces aggregated outputs based on the provided input variable parameters and the expected output attributes STRING No No
output.attributes The expected set of output attributes. These can be provided as a comma-separated list. Each attribute is denoted as '<name><space><type>'. e.g., 'output1 string, output2 long'. INT
LONG
FLOAT
DOUBLE
STRING
STRING
No No
input.attributes A set of input attributes to be considered when generating the expected output. This can be provided as a comma-separated list after output attributes. e.g., 'att1, att2'. INT
LONG
FLOAT
DOUBLE
STRING
STRING
No No
Extra Return Attributes
Name Description Possible Types
outputParameters The output parameters returned once the R script is run for each event. INT
LONG
FLOAT
DOUBLE
STRING
STRING

Examples EXAMPLE 1

@info(name = 'query1')
from weather#window.lengthBatch(2)#r:eval("c <- sum(time); m <- sum(temp); ", "c long, m double", time, temp) 
select * 
insert into dataOut;

This query runs the R script 'c <- sum(time); m <- sum(temp);' for every two events in a tumbling manner. Values are derived for two output parameters named 'c' and 'm' by considering the values of two other parameters named 'time' and 'temp' as the input.

evalSource (Stream Processor)

The R source Stream processor runs the R script loaded from a file for each event and produces aggregated outputs based on the input variable parameters provided and the expected output attributes.

Syntax

r:evalSource(<STRING> file.path, <INT|LONG|FLOAT|DOUBLE|STRING|STRING> output.attributes, <INT|LONG|FLOAT|DOUBLE|STRING|STRING> input.attributes)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
file.path The file path of the R script where this script is located uses the input variable parameters and produces the expected output attributes. STRING No No
output.attributes The expected output attributes. This can be provided and a string of comma-separated attribute names. Each attribute is denoted as <name><space><type>. e.g., 'output1 string, output2 long'. INT
LONG
FLOAT
DOUBLE
STRING
STRING
No No
input.attributes A set of input attributes to be considered when generating the expected output. This can be provided as a comma-separated list after output attributes. e.g., 'att1, att2'. INT
LONG
FLOAT
DOUBLE
STRING
STRING
No No
Extra Return Attributes
Name Description Possible Types
outputParameters The output parameters returned once the R script is run for each event. INT
LONG
FLOAT
DOUBLE
STRING
STRING

Examples EXAMPLE 1

@info(name = 'query1')
from weather#window.lengthBatch(2)#r:evalSource("src/test/resources/sample2.R", "m int, c float", time, temp)
select *
insert into dataOut;

This 'r' source function takes in a 'r' script file location and computes the output as defined in the file.