• Esper系列(九)NamedWindow语法create、Insert、select


    功能:用于存储一种或多种类型的事件的集合,并能对所存储的事件进行增删改查操作.

    CreateNameWindow

    根据已有的数据源构造

    格式:

    [context context_name] 
            create window window_name.view_specifications 
            [as] [select list_of_properties from] event_type_or_windowname
            [insert [where filter_expression]]

    说明:

    Window_name表示Window名称且具有全局唯一性,View_specification:表示过期策略;select子句表示需加入到新建window中的属性,数据源可以是已存在的事件或window;insert子句用于将已存在的window中的事件添加到新建的window中.

    自定义

    格式:

    [context context_name] 
    create window window_name.view_specifications [as] (column_name column_type 
      [,column_name column_type [,...])

    说明:

    Column_name表示属性名,column_type表示和苏醒类型,属性与属性之间用逗号分割。

    结合注解

    通过注解控制Listener中update收到的事件是Map还是数组。

    例子:

    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 语法一样。

    例子:

    // 创建window【myWindow】,过期策略为win:length_batch(3)
    String nwsql = "create window myWindow.win:length_batch(3) as orderEvent";
    EPStatement nwstate = epAdmin.createEPL(nwsql);
    // 插入orderEvent事件
    String insql = "insert into myWindow select * from orderEvent";
    EPStatement instate = epAdmin.createEPL(insql);
    // 查询myWindow中的数据
    String epsql = "select name as result from myWindow ";
    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中的事件达到某种关联后输出符合这个关联的事件或事件的部分属性。

    格式:

    on event_type[(filter_criteria)] [as stream_name]
    [insert into insert_into_def]
    select select_list
    from window_or_table_name [as stream_name]
    [where criteria_expression]
    [group by grouping_expression_list]
    [having grouping_search_conditions]
    [order by order_by_expression_list]

    说明:

    Event_type表示触发的事件(window、pattern),filter_criteria表示触发事件的限制条件,as stream_name表示给触发事件命别名(可省)

    例子:

    文件名:orderMainTest.java
    // 创建window
    String nwsql = "create window myWindow.win:length(3) as orderEvent";
    EPStatement nwstate = epAdmin.createEPL(nwsql);
    // 向window中插入数据
    String insql = "insert into myWindow select * from orderEvent";
    EPStatement instate = epAdmin.createEPL(insql);
    // 构造查询
    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。

  • 相关阅读:
    Python PEP8 编码规范 表达式和语句中的空格
    Python PEP8 编码规范 代码布局
    saltstack grains pillar
    logstash的output插件
    Logstash的插件
    elasticsearch查询及logstash简介
    ELK的使用
    ElasticSearch
    dockerfile
    docker网络模型
  • 原文地址:https://www.cnblogs.com/jianyuan/p/5028522.html
Copyright © 2020-2023  润新知