The latest version for DAS is WSO2 Data Analytics Server 3.1.0. View documentation for the latest release.
WSO2 Data Analytics Server is succeeded by WSO2 Stream Processor. To view the latest documentation for WSO2 SP, see WSO2 Stream Processor Documentation.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: corrected example

...

E.g. A stream named TempStream can be created with the following attributes as shown below. 

Anchor
Temperature Stream Example
Temperature Stream Example

Attribute NameAttribute Type
deviceIDlong
roomNoint
tempdouble
Code Block
languagesql
linenumberstrue
define stream TempStream (deviceID long, roomNo int, temp double);

...

SiddhiQL supports the following for query projection.

ActionDescription
Selecting required objects for projection

This involves selecting only some of the attributes in an input stream to be inserted into an output stream.

e.g., The following query selects only the  roomNo and temp attributes from the TempStream stream.

Code Block
languagesql
linenumberstrue
from TempStream 
select roomNo, temp
insert into RoomTempStream;
Selecting all attributes for projection

This involves selecting all the attributes in an input stream to be inserted into an output stream. This can be done by using the asterisk sign ( * ) or by omitting the select statement.

e.g., Use one of the following queries to select all the attributes in the TempStream stream.

Code Block
languagesql
linenumberstrue
from TempStream 
select *
insert into NewTempStream;

or

Code Block
languagesql
linenumberstrue
from TempStream 
insert into NewTempStream;
Renaming attributes

This involves selecting attributes from the input streams and inserting them into the output stream with different names.

e.g., The following query renames roomNo to roomNumber and temp to temperature

Code Block
languagesql
linenumberstrue
from TempStream 
select roomNo as roomNumber, temp as temperature
insert into RoomTempStream;
Introducing the default value

This involves adding a default value and assigning it to an attribute using as.

e.g.,

Code Block
languagesql
linenumberstrue
from TempStream 
select roomNo, temp, 'C' as scale
insert into RoomTempStream;
Using mathematical and logical expressions

This involves using attributes with mathematical and logical expressions to the precedence order given below, and assigning them to the output attribute using as .

Operator precedence

OperatorDistributionExample
 () Scope
Code Block
languagesql
(cost + tax) * 0.05
 IS NULL Null check
Code Block
languagesql
deviceID is null
 NOT Logical NOT
Code Block
languagesql
not (price > 10)
 *   /   %   Multiplication, division, modulo
Code Block
languagesql
temp * 9/5 + 32
 +   -   Addition, substraction
Code Block
languagesql
temp * 9/5 + 32
 <   <=   >   >=Comparisons: less-than, greater-than-equal, greater-than, less-than-equal
Code Block
languagesql
totalCost >= price * quantity 
 ==   !=   Comparisons: equal, not equal
Code Block
languagesql
totalCost 
>
!= price * quantity 
INContains in table
Code Block
languagesql
roomNo in ServerRoomsTable
ANDLogical AND
Code Block
languagesql
temp < 40 and (humidity < 40 or humidity >= 60)
ORLogical OR
Code Block
languagesql
temp < 40 and (humidity < 40 or humidity >= 60)

e.g., Converting Celsius to Fahrenheit and identifying server rooms

Code Block
languagesql
linenumberstrue
from TempStream 
select roomNo, temp * 9/5 + 32 as temp, 'F' as scale, roomNo >= 100 and roomNo < 110 as isServerRoom
insert into RoomTempStream;

 



Functions

A function consumes zero, one or more function parameters and produces a result value.

...

Time is a special parameter that can we defined using the time value as int and its unit type as <int> <unit>. Following are the supported unit types, Time upon execution will return its expression in the scale of milliseconds as a long value. 

UnitSyntax
Yearyear | years
Monthmonth | months
Weekweek | weeks
Dayday | days
Hourhour | hours
Minutesminute | minutes | min
Secondssecond | seconds | sec
Millisecondsmillisecond | milliseconds

E.g. Passing 1 hour and 25 minutes to test function. 

...

The above syntax contains the following:

ElementDescription
<event window name>
A unique name for the window.
<attribute name> <attribute type>
These elements define a set of attributes assigned specific types.

<window type>

Any inbuilt window type available in Siddhi. For the complete list of available window types, see Inbuilt Windows.

<output event type>

The possible values for this parameter are as follows:

  • output current events : Windows with this output event type emit only current events.
  • output expired events : Windows with this output event type emit only expired events.
  • output all events : Windows with this output event type emit both current and expired events.

If the output event type is not specified for an event window, it emits both current and expired events.

Sample event window definitions

...

The query for inserting events into a window is similar to the query for inserting events into event streams where the insert into <window name> code snippet is used. To restrict the events inserted into the window by a specific category, use one of the following key words between the insert and into keywords.

KeywordPurpose
current events To insert only current events into the event window.
expired events To insert only expired events into the event window.
all events To insert both current and expired events into the event window.

e.g., The following query inserts both current and expired events from an event stream named sensorStream to an event window named sensorWindow.

...

The parameters used in the query are as follows.

ParameterDescription

priority

The logging priority. Possible values are INFODEBUGWARNFATALERROROFF, and TRACE. If no value is specified for this parameter, INFO is printed as the priority by default.
logMessage This parameter allows you to specify a message to be printed in the log.
isEventLogged This parameter specifies whether the event body should be included in the log. Possible values are true and false. If no value is specified, the event body is not printed in the log by default.

The following examples illustrate the variations of the Siddhi logger.

...

  • Function Extension 
  • Aggregate Function Extension 
  • Window Extension 
  • Stream Function Extension
  • Stream Processor Extension

 


---------------------

Children Display