Create Rule¶
This service of API is used for operation on creating CEP rules for a tenant. A user can create a wide variety of CEP rules with joining,filtering,aggregation etc functionalities and route the output to a topic.Input and output of CEP is topic.
Following is the URL for CEP create rule.
POST http://<domain name>/cep/v2.0/rules
CEP functionality can be classified into joining/filtering and pure aggregations.CEP rules can be wired and output of one CEP rule can be fed to another CEP rule. Classification of CEP rules is provided below :-
Following is sample json for creating rule :-
{
"ruleName": "JoiningSample1",
"selectClause": "s1.temp as currtemp,s2.humidity as currhumidity,s1.feature as feature,s1.starttime as s1time,s2.starttime as s2time",
"joinClause": "(s1.feature = s2.feature) AND abs(s1.starttime - s2.starttime) <= 60",
"whereClause": "currtemp > 40 AND currhumidity > 90",
"groupByField": "feature",
"triggerInterval": "30",
"windowDuration": "",
"input": [{
"alias": "s1",
"topic": "test1",
"properties": [
"temp"
]
},
{
"alias": "s2",
"topic": "test2",
"properties": [
"humidity"
]
}
],
"output": "outputjoin4"
}
Description of create rule json parameters is defined in below table
Parameter
Required
Description
ruleName
true
name of CEP rule,this has to be unique for the rules across tenants
selectClause
true
SQL interface for user, standard sql select query along with some supported spark sql specific select query with the help of keywords described below
whereClause
false
Condition clause with the alias or field already defined in “selectClause”, Example: tempdiff <= 0
joinClause
false
Join condition between two/many streams,based on common field,difference of event time in two streams along with optional filtering condition, Example: (s1.feature = s2.feature) AND abs(s1.starttime - s2.starttime) <= 60 AND (s1.temp > 40) AND (s2.humidity > 90)
groupByField
false
Similar to sql groupBy,output will be grouped based on the values in feature/sensor field in the input data
triggerInterval
false
User specified interval at which output will be triggered ,Example: 30(seconds)
windowDuration
false
Duration of window in seconds during joining or aggregation operations, Example: 30(seconds)
slidingDuration
false
Duration of slidingInterval in seconds(applicable only for purely aggregation functions), Example: 10(seconds)
input
true
- alias - alias/streamname to uniquely identify topic
topic - input topics from where cep rule will consume the data before processing properties - property/properties to be selected from the input topic
output
true
output topic where the output after processing will be written into
Here is the list of the TCUP CEP keyword, that can be used in the selectClause
Keyword
Description
rank
It sorts the fields by descending order of the values of the fields and assign rank to each field after sorting within the window.
lag(nth)
It returns the immediate previous nth value of the field within the window. lag(1) means immediate previous i.e n start with 1.
lead(nth)
It returns the immediate next nth value of the field within the window. lead(1) means immediate next i.e n start with 1.