0

I have a userStream having name,address,status

I want to store this details in UserDetailsTable (In memory table)

Result of UserDetailsTable is below

"Jose",  "address1","false" 
"Rockey","address2","false" 
"sibin", "address3","false"

I have another triggerStream having name,triggerStatus

"Rockey","delete"
"Jose"  ,"update"

Case 1) When triggerStream comes as "Rockey", I want to join this triggerStream with UserDetailsTable according to (name and triggerStatus) and delete the row from UserDetailsTable.

Case 2) When triggerStream comes as "Jose", I want to join this triggerStream with UserDetailsTable according to (name and triggerStatus) and update the status as "true" in UserDetailsTable.

Final state of UserDetailsTable is below.

"Jose",  "address1","true"
"sibin", "address3","false"

how can able to do this with WSO2 CEP?

Community
  • 1
  • 1
sarath
  • 767
  • 12
  • 19

1 Answers1

1

Assuming you've defined the streams and tables and an insert query to populate the in-memory table.

For case 1, you can use a delete query as follows with a condition:

from triggerStream 
delete userDetailsTable
on name == userDetailsTable.name and triggerStatus == userDetailsTable.status;

If you want to delete specific names such as 'rockey' you can add a filter to the above query as follows:

from triggerStream[name == 'rockey'] 
delete userDetailsTable
on name == userDetailsTable.name and triggerStatus == userDetailsTable.status;

For case 2, you can use an update query with a filter for 'jose' as follows:

from triggerStream[name == 'jose']
select name, triggerStatus as status 
update userDetailsTable on name == userDetailsTable.name 

in this query, we rename the attribute 'triggerStatus' as 'status' to make it equal to table's attribute name.

Rajeev Sampath
  • 2,739
  • 1
  • 16
  • 19