简体   繁体   English

使用WSO2 CEP更新MySQL数据库

[英]Update MySQL Database using WSO2 CEP

Is there any way to update the MySQL Db without updating the empty values in the stream. 有什么方法可以更新MySQL Db而不更新流中的空值。 If my input data stream contains some empty values, currently that empty value is indicate using "data_empty" value. 如果我的输入数据流包含一些空值,则当前使用“ data_empty”值指示该空值。 At that time CEP update the DB with that value ("data_empty"). 那时,CEP使用该值(“ data_empty”)更新数据库。 My goal is without updating that empty value update the rest of things. 我的目标是不更新空值即可更新其余内容。 Is it possible to do using siddhi and WSO2 CEP. 是否可以使用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;

It's sort of difficult to update only the non-empty (not 'data_empty' in your scenario) values to the database. 仅将非空值(在您的方案中不是'data_empty')值更新到数据库有点困难。 However in Siddhi, there's a function called ifThenElse(condition, value if true, value if false) , which can be used in your scenario. 但是在Siddhi中,有一个名为ifThenElse(condition, value if true, value if false)的函数,可以在您的方案中使用。 Refer to the below sample execution plan for you to get an idea on using ifThenElse() and table updating (similar to your usecase). 请参考下面的示例执行计划,以了解如何使用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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM