www.espertech.comDocumentation
A paragraph that contains a scenario consisting of a sequence of events and time must begin with %esperscenario
.
A scenario is a list of instructions with one instruction per line. Each instruction can either:
Set or advance to a given time.
Send an event.
Advance time relative to the current time.
When running a paragraph that contains a scenario, the notebook performs these actions:
Allocates a runtime.
Sets the runtime current time.
Deploys all EPL that compiled successfully.
Validates and executes each instruction.
Displays EPL statement output events, by default as an HTML table.
When running a scenario, the default start time is 1970-01-01 00:00:00.000
unless the scenario, in the first instruction, sets another given time.
Current time is represented by a predefined long-type millisecond value by name t
.
To set a time or advance to a given time, enter an assignment of time t
to a string date-time value as follows:
t = "2001-01-01 08:00:00.000"
If the time is newer than the current time the time advances to the provided time.
To send an event, enter an assignment of event type name to an array of name-value pairs in curly braces. For example:
MyEvent = {intProperty = 0, stringProperty = 'abc'}
You may use curly braces for array and collection values, like shown here:
MyEvent = {stringArray = {'a', 'b'}, listProperty = {1, 2, 3}}
The scenario interpreter converts array values to the given type, for example when the event type was declared as create schema MyEvent(stringArray string[])
the interpreter converts values for stringArray
to array of string.
For object-array please use java.lang.Object[] as type. The interpreter supports array values for these types as well: java.util.Collection, java.util.List, java.util.ArrayList and java.util.Vector.
To assign the value of an EPL expression evaluation to an event property, use the eval function and specify the expression string. The next example assigns the result of the expression 5*5
to intProperty
and the result of the myFunction
function to stringProperty
.
MyEvent = {intProperty = eval("5*5"), stringProperty = eval("myFunction('some value')")}
To assign a value to a Date or Calendar-typed event property you may specify a string-value that contains a datetime value following one of these formats:
Table 3.1. Date Formats
Format |
---|
yyyy-MM-dd HH:mm:ss |
yyyy-MM-dd HH:mm:ss.SSS |
yyyy-MM-dd HH:mm:ss.SSSZ |
yyyy-MM-dd'T'HH:mm:ss |
yyyy-MM-dd'T'HH:mm:ss.SSS |
yyyy-MM-dd'T'HH:mm:ss.SSSZ |
For example:
MyEvent = {dateOrCalendarPropertyOne = '2002-09-30 9:00:00', dateOrCalendarPropertyTwo = '2002-09-30 9:00:00.000', dateOrCalendarPropertyThree = '2002-09-30 9:00:00.000+0100'}
Events can be nested. Place the event properties of each nested event in curly braces. The nesting level is unlimited and nested classes are supported.
To illustrate, assume an order event that has a single order item as a nested event:
create schema OrderItem(itemId string, price double); create schema OrderEvent(orderId string, item OrderItem);
The sample order event with a single order item is:
OrderEvent={orderId='O1', item={itemId='I1', price=100}}
For multiple nested events, use curly braces to separate each event.
In below schema each order event can have multiple order items:
create schema OrderItem(itemId string, price double); create schema OrderEvent(orderId string, items OrderItem[]);
The sample order event with multiple order items is:
OrderEvent={orderId='O1', items={{itemId='I1', price=100}, {itemId='I2', price=50}}}
When using JavaBean-style events you must make sure that there are getters and setters for nested objects.
To advance time relative to current time, enter an assignment of time t
to t
plus a time period. For example:
t = t.plus(10 minutes 5 seconds)
The EPL "plus" date-time enumeration method and the time period parameter documentation in Esper docs have more information.
Alternatively, you may also advance time in millisecond steps by adding milliseconds to t:
t = t + 1000
The above example adds 1 second (1000 milliseconds) to the current time.
You can create a separate paragraph, specify %espersetup setup
and run that paragraph. After running the paragraph presents a form with output options.
You can decorate your statements with the @Audit
annotation for audit-level information on statement execution (use a %espersetup setup
paragraph to enable audit output).