createCEPEngine

Syntax

createCEPEngine(name, monitors, dummyTable, eventSchema, [deserializeParallelism=1], [timeColumn], [eventQueueDepth=1024], [outputTable], [dispatchKey], [dispatchBucket], [useSystemTime=true], [eventTimeField="eventTime"])

Details

The CEP engine processes real-time events primarily by subscribing to heterogeneous stream tables (through subscribeTable). Event data can be written to these tables either by using the replay function or through APIs.

Note: To write events directly to the CEP engine, use the appendEvent function. This function enables direct appending of events to the event input queue.

Parameters

name is a string scalar indicating the name of the CEP engine. It consists of letters, digits, and underscores(_) and must start with a letter.

monitors is metacode or a tuple of metacode containing one or more constructors of Monitor class. If multiple constructors are specified, the monitor objects will be constructed in order. For the instructions on how to define a monitor, refer to Defining Monitors.

dummyTable is a non-partitioned in-memory table or a stream table. The columns are in the following order:

(1) A time column of TIMESTAMP type (if eventTimeField is specified);

(2) A STRING column indicating the events;

(3) A BLOB column that stores the serialized result of each event;

eventSchema is a scalar or vector of class definition of event types, indicating the events (subscribed from APIs or plugins) to be processed. For the instructions on how to define an event, refer to Defining Events.

deserializeParallelism (optional) is an integer that specifies the number of workers to deserialize the subscribed stream table. The default value is 1.

timeColumn (optional) is a STRING scalar or vector indicating the time column(s) of dummyTable. If specified, it is used as the initialized event time for event streams.

eventQueueDepth (optional) is an integer that specifies the queue depth for event input and output queue. The default value is 1024.

outputTable (optional) can be specified as a single or multiple serializers, each returned by streamEventSerializer. It is used with the emitEvent function to output events to the table(s) specified by the serializer(s). The serialization and output processes of different serializers are independent and executed concurrently.

dispatchKey (optional) is a string scalar indicating the event fields.

  • If specified,the engine creates sub-engines based on the number of unique values of the event field.

  • If not specified, the engine only creates a single sub-engine with the same name as CEP engine (name).

dispatchBucket (optional) is an integer indicating the number of hash buckets. It is used to group the specified event field (dispatchKey) using hash algorithm. To specify this parameter, dispatchKey must be specified. If specified, the engine creates the sub-engines based on bucket numbers specified by dispatchBucket.

useSystemTime (optional) is a Boolean value indicating whether the calculations are performed based on the system time (in millisecond) when the event is ingested into the engine. The default value is true. If set to false, the calculations are performed based on the timeColumn.

eventTimeField (optional) is a STRING scalar or vector indicating the time column(s) of events. It only takes effect when useSystemTime = false. It is a scalar if all events use the same time column name. Otherwise, it is a vector of the same length as eventSchema, where each element represents the time column for each event. This parameter is required if event streams are ingested into the CEP engine using appendEvent.

Examples

class MarketData{
    market :: STRING
    code :: STRING
    price :: DOUBLE
    qty :: INT
    def MarketData(m,c,p,q){
        market = m
        code = c
        price = p
        qty = q
    }
}

class Orders{
    trader :: STRING
    market :: STRING
    code :: STRING
    price :: DOUBLE
    qty :: INT
    def Orders(t, m,c,p,q){
        trader = t
        market = m
        code = c
        price = p
        qty = q
    }
}

class Trades{
    trader :: STRING
    market :: STRING
    code :: STRING
    price :: DOUBLE
    qty :: INT
    def Trades(t, m,c,p,q){
        trader = t
        market = m
        code = c
        price = p
        qty = q
    }
}

share streamTable(array(STRING, 0) as eventType, array(BLOB, 0) as blobs) as MarketDataChannel
serializer1 = streamEventSerializer(name=`MarketDataChannel, eventSchema=[MarketData], outputTable=MarketDataChannel)

share streamTable(array(STRING, 0) as eventType, array(BLOB, 0) as blobs) as OrdersChannel
serializer2 = streamEventSerializer(name=`OrdersChannel, eventSchema=[Orders], outputTable=OrdersChannel)

share streamTable(array(STRING, 0) as eventType, array(BLOB, 0) as blobs) as TradesChannel
serializer3 = streamEventSerializer(name=`TradesChannel, eventSchema=[Trades], outputTable=TradesChannel)

class SimpleShareSearch:CEPMonitor {
	// Constructor
	def SimpleShareSearch(){
	}
	def processMarketData(event){
        emitEvent(event,,"MarketDataChannel")
    }
    def processOrders(event){
        emitEvent(event,,"OrdersChannel")
    }
    def processTrades(event){
        emitEvent(event,,"TradesChannel")
    }
	// After creating the CEP sub-engine, the system automatically instantiates the SimpleShareSearch class as a Monitor instance and invokes the onload function.
	def onload() {
		// Listen to StockTick events
		addEventListener(handler=processMarketData, eventType="MarketData", times="all")
		addEventListener(handler=processOrders, eventType="Orders", times="all")
		addEventListener(handler=processTrades, eventType="Trades", times="all")
	}
}

dummy = table(array(STRING, 0) as eventType, array(BLOB, 0) as blobs)
engine = createCEPEngine(name='cep1', monitors=<SimpleShareSearch()>, dummyTable=dummy, eventSchema=[MarketData,Orders,Trades], outputTable=[serializer1,serializer2,serializer3])

m= MarketData("m", "c", 10.0, 100)

appendEvent(engine, m)

o = Orders("a","m", "c", 10.0, 100)
t = Trades("a","m", "c", 10.0, 100)

appendEvent(engine, o)
appendEvent(engine, t)

Related functions: addEventListener, dropStreamEngine, getCEPEngineStat, stopSubEngine