updateDataViewItems
Syntax
updateDataViewItems(engine, keys, valueNames, newValues)
Details
Updates the data with the specified keys from a data view engine. If the key column specified in keys does not exist, an error will be raised during deletion.
The updateDataViewItems functions can be called within a CEP engine
context or outside of it.
-
Within a CEP engine: The system will first attempt to locate a data view engine handle with specified engine within the current CEP engine context. If a matching engine is found, the corresponding update operation will be performed. If no such engine, the system will then search for a data view engine with the same handle outside of the CEP engine context.
-
Outside a CEP engine: The system will search for and perform corresponding operation on a data view engine handle with specified engine only from the context outside of any CEP engine.
Parameters
engine is either the handle or the name of a data view engine.
keys is a scalar, vector, or tuple, indicating the key(s) to be updated.
valueNames is a STRING scalar or vector, indicating the columns (from the
outputTable of createDataViewEngine) to be updated.
newValues is a scalar, vector, or tuple, indicating the updated values.
Returns
None.
Examples
class trades{
trader :: STRING
market :: STRING
code :: STRING
price :: DOUBLE
qty :: INT
eventTime :: TIMESTAMP
def trades(t, m, c, p, q){
trader = t
market = m
code = c
price = p
qty = q
eventTime = now()
}
}
class mainMonitor:CEPMonitor{
tradesTable :: ANY
isBusy :: BOOL
def mainMonitor(){
tradesTable = array(ANY, 0)
isBusy = false
}
def updateTrades(event)
def updateTrades2(event)
def unOnload(){
undef('traderDV', SHARED)
}
def onload(){
addEventListener(updateTrades, `trades, , "all",,,,,"trades1")
addEventListener(updateTrades2, `trades, , "all",,,,,"trades2")
traderDV = streamTable(array(STRING, 0) as trader, array(STRING, 0) as market, array(SYMBOL, 0) as code, array(DOUBLE, 0) as price, array(INT, 0) as qty, array(INT, 0) as tradeCount, array(BOOL, 0) as busy, array(DATE, 0) as orderDate, array(TIMESTAMP, 0) as updateTime)
share(traderDV, 'traderDV')
createDataViewEngine('traderDV', objByName('traderDV'), `trader, `updateTime, true)
}
def updateTrades(event) {
tradesTable.append!([event.trader, event.market, event.code, event.price, event.qty])
getDataViewEngine('traderDV').append!(table(event.trader as trader, string() as market, string() as code, 0.0 as price, 0 as qty, 0 as tradeCount, false as busy, date(event.eventTime) as orderDate))
updateDataViewItems('traderDV', event.trader, ['market', 'code', 'price', 'qty', 'tradeCount'], [event.market, event.code, event.price, event.qty, tradesTable.size()])
}
def updateTrades2(event) {
tradesTable.append!([event.trader, event.market, event.code, event.price, event.qty])
getDataViewEngine('traderDV').append!(table(event.trader as trader, string() as market, string() as code, 0.0 as price, 0 as qty, 0 as tradeCount, false as busy, date(event.eventTime) as orderDate))
updateDataViewItems('traderDV', event.trader, ['market', 'code', 'price', 'qty', 'tradeCount'], [event.market, event.code, event.price, event.qty, tradesTable.size()])
}
}
dummy = table(array(TIMESTAMP, 0) as eventTime, array(STRING, 0) as eventType, array(BLOB, 0) as blobs)
engineCep = createCEPEngine('cep1', <mainMonitor()>, dummy, [trades], 1, 'eventTime', 10000)
trade1 = trades('t1', 'sz', 's001', 11.0, 10)
go
appendEvent(engineCep, trade1)
monitors = getCEPEngineMonitor('cep1',"cep1","mainMonitor")
listeners = monitors.getEventListener()
print(listeners)
listeners['trades1'].terminate()
print(listeners)
Related functions: createCEPEngine, createDataViewEngine, deleteDataViewItems, dropDataViewEngine, getDataViewEngine
