使用WSO2 CEP更新MySQL数据库

时间:2016-04-28 11:38:23

标签: mysql wso2 wso2cep siddhi

有没有办法更新MySQL Db而不更新流中的空值。如果我的输入数据流包含一些空值,则当前使用" data_empty"表示空值。值。那时CEP用该值更新DB(" data_empty")。我的目标是不更新那个空值来更新其余的东西。是否可以使用siddhi和WSO2 CEP。

@Plan:name('DBUpdateExecutionPlan')
@Import('testStream:1.0.0')
define stream input (id string, param1 string, param2 string);

@Export('testOutStream:1.0.0')
define stream output (id string, param1 string, param2 string);

@from(eventtable = 'rdbms' , datasource.name = 'MYSQL' , table.name = 'cep')
define table cepTable (id string, param1 string, param2 string) ;

from input#window.time(0 sec)
select * 
update cepTable on id == cepTable.id;

1 个答案:

答案 0 :(得分:3)

将数据库中的非空(不是“场景中的数据空间”值)值更新很困难。但是在Siddhi中,有一个名为ifThenElse(condition, value if true, value if false)的函数,可以在您的场景中使用。请参阅以下示例执行计划,以了解使用ifThenElse()和表更新(类似于您的用例)。

@Plan:name('IfThenElseExecutionPlan')

@Import('inputStream:1.0.0')
define stream dataIn (roomId int, roomType string, roomTemp float);

@Export('outputStream:1.0.0')
define stream dataOut (roomId int, roomType string, roomTemp float);

@From(eventtable='rdbms', datasource.name='cepdatabase', table.name='roomTable')
define table roomTable (roomId int, roomType string, roomTemp float);

from dataIn[not((roomTable.roomId == roomId) in roomTable)]
insert into updateStream;

from dataIn join roomTable
on roomTable.roomId == dataIn.roomId
select  dataIn.roomId as roomId, 
        ifThenElse(dataIn.roomType=='data_empty', roomTable.roomType, dataIn.roomType) as roomType, 
        ifThenElse(dataIn.roomTemp==0.0f, roomTable.roomTemp, dataIn.roomTemp) as roomTemp
insert into updateStream;

from updateStream
insert overwrite roomTable
on roomTable.roomId == roomId;