On-Delete With Named Windows
功能:在Named Windows中删除事件.
格式:
1 | on event_type[(filter_criteria)] [as stream_name] |
2 | delete from window_or_table_name [as stream_name] |
3 | [where criteria_expression] |
说明:
Criteria_expression为删除事件的条件.
例子:
1 | // 构造window |
2 | String nwsql = "create window myWindow.win:keepall() as orderEvent"; |
3 | EPStatement nwstate = epAdmin.createEPL(nwsql); |
4 | // 想window中插入事件 |
5 | String insql = "insert into myWindow select * from orderEvent"; |
6 | EPStatement instate = epAdmin.createEPL(insql); |
7 | // delete |
8 | String epsql = "on orderBean (value>50) as ob delete from myWindow as mw where mw.salary=111"; |
Triggered Select+Delete: the On Select Delete clause
功能:从named window查询出结果的同时删掉查询结果.
格式:
1 | // 构造window |
2 | String nwsql = "create window myWindow.win:keepall() as orderEvent"; |
3 | EPStatement nwstate = epAdmin.createEPL(nwsql); |
4 | // 向windwo中插入事件 |
5 | String insql = "insert into myWindow select * from orderEvent"; |
6 | EPStatement instate = epAdmin.createEPL(insql); |
7 | // select+delete |
8 | String epsql = "on orderBean (value>50) as ob select and delete * from myWindow as mw where mw.salary=111"; |
注意:最后执行的查询加删除EPL中,删除的是mw.salary=111中的orderBean事件和myWindow中的事件.
On-Update With Named Windows
功能:更新window中事件.
格式:
1 | on event_type[(filter_criteria)] [as stream_name] |
2 | update window_or_table_name [as stream_name] |
3 | set mutation_expression [, mutation_expression [,...]] |
4 | [where criteria_expression] |
例一:
1 | // 创建window |
2 | String nwsql = "create window myWindow.win:keepall() as orderBean"; |
3 | EPStatement nwstate = epAdmin.createEPL(nwsql); |
4 | // 向window中插入数据 |
5 | String insql = "insert into myWindow select * from orderBean"; |
6 | EPStatement instate = epAdmin.createEPL(insql); |
7 | // 更新操作 |
8 | String epsql = "on orderEvent(salary>0) as oe update myWindow as mw set mw.key=\"chenx\",mw.value=100 where mw.value=111 "; |
9 | EPStatement epstate = epAdmin.createEPL(epsql); |
功能:
当orderEvent 事件中的salary属性大于零,将myWindow中事件属性value值为111修改为100,并将key修改为 chenx。
说明:
1、在Window的update操作中,orderBean事件必须实现Serializable接口;
2、orderBean事件的属性必须要可写,且不能存在嵌套属性(Map、List等);
3、XML格式的事件不能通过此语句更新
例二:
1 | // 更新操作 |
2 | String epsql = "on orderEvent(salary>0) as oe update myWindow as mw set mw.key=\"chenx\",mw.value=100 where oe.salary=111 "; |
3 | EPStatement epstate = epAdmin.createEPL(epsql); |
功能:这个更新语句与上一个更新语句差别在于where的条件判读不同,当orderEvent事件中的salary大于0且等于111的时候,将myWindow中的所有事件的key属性修改为 chenx,value属性修改为100。
例三:
1 | on UpdateEvent as upd |
2 | update MyWindow as win |
3 | set field_a = 1, |
4 | field_b = win.field_a, |
5 | field_c = initial.field_a |
说明:
field_a被更新为1,然后用修改后的field_a赋值给field_b,那么field_b实际上也变成1了。但是如果想用更新前的field_a的值赋给field_c,那么就要写成initial.field_a。initial是关键字,所以不能省略。