Esper系列(九)NamedWindow语法create、Insert、select
功能:用于存储一种或多种类型的事件的集合,并能对所存储的事件进行增删改查操作.
CreateNameWindow
根据已有的数据源构造
格式:
| 1 | [context context_name] |
| 2 | create window window_name.view_specifications |
| 3 | [as] [select list_of_properties from] event_type_or_windowname |
| 4 | [insert [where filter_expression]] |
说明:
Window_name表示Window名称且具有全局唯一性,View_specification:表示过期策略;select子句表示需加入到新建window中的属性,数据源可以是已存在的事件或window;insert子句用于将已存在的window中的事件添加到新建的window中.
自定义
格式:
| 1 | [context context_name] |
| 2 | create window window_name.view_specifications [as] (column_name column_type |
| 3 | [,column_name column_type [,...]) |
说明:
Column_name表示属性名,column_type表示和苏醒类型,属性与属性之间用逗号分割。
结合注解
通过注解控制Listener中update收到的事件是Map还是数组。
例子:
| 1 | String nwsql = "@EventRepresentation(array=true) create window myWindow.win:length_batch(3) as orderEvent"; |
说明:
其中array=true表示数组,array=false表示Map
Inserting Into Named Windows
与前面章节的事件Insert into 语法一样。
例子:
| 1 | // 创建window【myWindow】,过期策略为win:length_batch(3) |
| 2 | String nwsql = "create window myWindow.win:length_batch(3) as orderEvent"; |
| 3 | EPStatement nwstate = epAdmin.createEPL(nwsql); |
| 4 | // 插入orderEvent事件 |
| 5 | String insql = "insert into myWindow select * from orderEvent"; |
| 6 | EPStatement instate = epAdmin.createEPL(insql); |
| 7 | // 查询myWindow中的数据 |
| 8 | String epsql = "select name as result from myWindow "; |
| 9 | EPStatement epstate = epAdmin.createEPL(epsql); |
| 10 | epstate.addListener(new orderListener()); |
说明:
1、创建完myWindow后,myWindow中的数据集还是空,必须在insert数据后才会有数据;
2、当执行查询操作时,先检查是否满足创建Window中的过期策略,再检查是否满足查询语句中的过滤条件,只有在两边条件都满足的情况下,才会将事件输出;
3、若将查询语句改为select name as result from myWindow.win:length_batch(3)执行将会报错,因为在创建window中应使用了win的view,所以在查询语句中不能再使用;
4、select句子中的filter如果使用了variable,当变量的值在句子创建后改变了,引擎不会读取新的值。
On-Select With Named Windows
Named Windows中一种更好的查询方式,可以设置这个触发事件满足什么要求才可触发,或者这个触发事件和window中的事件达到某种关联后输出符合这个关联的事件或事件的部分属性。
格式:
| 1 | on event_type[(filter_criteria)] [as stream_name] |
| 2 | [insert into insert_into_def] |
| 3 | select select_list |
| 4 | from window_or_table_name [as stream_name] |
| 5 | [where criteria_expression] |
| 6 | [group by grouping_expression_list] |
| 7 | [having grouping_search_conditions] |
| 8 | [order by order_by_expression_list] |
说明:
Event_type表示触发的事件(window、pattern),filter_criteria表示触发事件的限制条件,as stream_name表示给触发事件命别名(可省)
例子:
文件名:orderMainTest.java
| 1 | // 创建window |
| 2 | String nwsql = "create window myWindow.win:length(3) 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 | // 构造查询 |
| 8 | String epsql = "on orderBean (value>50) as ob select * from myWindow as mw"; |
注意:
1、最后的构造查询EPL语句中,返回的数据有myWindow中的事件也有orderBean的事件。
2、若只想返回myWindow中的事件需将EPL改为:on orderBean (value>50) as ob select mw.* from myWindow as mw。
Esper系列(九)NamedWindow语法create、Insert、select的更多相关文章
- Esper系列(十)NamedWindow语法delete、Select+Delete、Update
On-Delete With Named Windows 功能:在Named Windows中删除事件. 格式: 1 , 4 field_b = win.field_a, 5 field_ ...
- Esper系列(十一)NamedWindow语法Merge、Queries、Indexing、Dropping
On-Merge With Named Windows 功能:对window中的insert.update.delete操作进行组合运用. 格式: 1 "; 14 15 Sys ...
- 使用INSERT…SELECT语法插入记录(三十二)
前面,我们在谈INSERT语句时,使用两种语句:INSERT…SELECT 和 INSERT…VALUES. INSERT…SELECT可以使用子查询.因为在写SELECT时. *** = ...
- Oracle中复制表的方法(create as select、insert into select、select into)
转: Oracle中复制表的方法(create as select.insert into select.select into) 2018-07-30 22:10:37 小白白白又白cdllp 阅读 ...
- SQL系列(十二)—— insert update delete
前言 这个系列的前面都一直在介绍查询select.但是SQL中十分广泛,按对数据的不同处理可以分为: DML:全称Data Manipulation Language,从名字上可以看出,DML是对数据 ...
- 懒人小工具:T4自动生成Model,Insert,Select,Delete以及导出Excel的方法
之前写了篇文章,懒人小工具:[自动生成Model,Insert,Select,Delete以及导出Excel的方法](http://www.jianshu.com/p/d5b11589174a),但是 ...
- SQL语法基础之SELECT
SQL语法基础之SELECT 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.SELECT查看帮助信息 1>.查看SELECT命令的帮助信息 mysql> ? SEL ...
- 懒人小工具:T4生成实体类Model,Insert,Select,Delete以及导出Excel的方法
由于最近公司在用webform开发ERP,用到大量重复机械的代码,之前写了篇文章,懒人小工具:自动生成Model,Insert,Select,Delete以及导出Excel的方法,但是有人觉得这种方法 ...
- oracle 中 insert select 和 select insert 配合使用
Insert Into select 与 Select Into 哪个更快? 在平常数据库操作的时候,我们有时候会遇到表之间数据复制的情况,可能会用到INSERT INTO SELECT 或者 SEL ...
随机推荐
- 关于Mysql数据库longblob格式数据的插入com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V问题分析
当数据库字段为blob类型时 ,我们如果使用PreparedStatement中的setBinaryStream(int,InputStream,int)方法需要注意 在向blob字段类型中插入数据时 ...
- stm32类型cl、vl、xl、ld、md、hd的含义
- startup_stm32f10x_ld_vl.s: for STM32 Low density Value line devices - startup_stm32f10x_ld.s: for ...
- 【intellij】异常信息汇总
Application Server was not connected before run configuration stop, reason: javax.management.Instanc ...
- 《深入理解计算机系统》C程序中常见的内存操作有关的典型编程错误
对C/C++程序员来说,内存管理是个不小的挑战,绝对值得慎之又慎,否则让由上万行代码构成的模块跑起来后才出现内存崩溃,是很让人痛苦的.因为崩溃的位置在时间和空间上,通常是在距真正的错误源一段距离之后才 ...
- margin负值的使用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Matlab 文件命名规则
Matlab 文件命名规则 1.文件名命名要用英文字符,第一个字符不能是数字和下划线. 2.文件名不要取为matlab的一个固有函数,m文件名的命名尽量不要是简单的英文单词,最好是由大小写英文.数字. ...
- java修改远程服务器密码
积累: 1. echo 用户名:新密码 | chpasswd
- [dp]HDOJ4960 Another OCD Patient
题意: 给一个n, 第二行给n堆的价值v[i], 第三行给a[i]. a[i]表示把i堆合在一起需要的花费. 求把n堆变成类似回文的 需要的最小花费. 思路: ①记忆化搜索 比较好理解... dp[ ...
- bitset学习小记
Cplusplus官网的资料: http://www.cplusplus.com/reference/bitset/bitset/ http://www.cplusplus.com/reference ...
- asp.net中GridView的CheckedUnBindCheckBox属性
1. 获取GridView中CheckBox所选行的字段,即使是在绑定了数据源的时候,也可以获取选中的CheckedUnBindCheckBox对应的各个列的字段 使用时根据实际情况适当的修改即可. ...