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

Scala Extension

This extension allows you to include Scala functions within the Siddhi Query Language.

Scala function

Syntax

define function <function name>[<language name>] return <return type> {

   <operation of the function>

};
Extension TypeEval Script
DescriptionThe <operation of the function> is an operation of the <function name> that is defined in the <language name> language, and the output is returned in the <return Type> specified.
Parameters
  • function name: The name of the function.
  • language name: The language of the script. In this scenario, it should be Scala.
  • return type: The return type of the function (int, long, float, double, string, bool or object).
  • operation of the function: The logic of the function.
Example

define function concatFunction[Scala] return string {

   var concatenatedString =

    for(i <- 0 until data.length){

        concatenatedString += data(i).toString

    }

    concatenatedString

};

The above function takes n (variable) number of strings, concatenates them and returns the output. Input parameters are automatically input as an array.

A stream can be defined as follows.

define stream TempStream(deviceID long, roomNo int, temp double);

The eval script defined above can be used in this stream as follows.

from TempStream

select concatFunction(roomNo,deviceID) as id, temp  

insert into DeviceTempStream;