WSO2 DAS SiddhiQL:初始化事件表并在之后更新

时间:2017-06-27 10:02:20

标签: wso2 complex-event-processing wso2-das siddhi

我有一些相关的问题:

  1. Fisrt,我想初始化一个事件表,其中包含默认值和100行,如下图所示:
  2. How I want to initialize my event table named 'counterTable'.

    1. 其次,初始化完成后,我想更新此表。查询1执行完成后,如何在同一执行计划中执行query2?

    2. 要完成,我有一个'altitude'属性的事件。在我的执行计划中,对于每个事件,我想增加事件表的每一行count1,其中num列小于alitude。我试过了,但这并没有增加所有行的数量。

      FROM inputStream JOIN counterTable
      SELECT count1+1 as count1, altitude as tempNum
      update counterTable on counterTable.count1 < tempNum;
      
      FROM inputStream JOIN counterTable
      SELECT counterTable.num as theAltitude, counterTable.count1 as countAltitude
      INSERT INTO outputStream;
      

2 个答案:

答案 0 :(得分:0)

  1. 如果要在每次部署执行计划时进行初始化,则应使用内存事件表(如下所示)。否则,您只需使用RDBMS event table,它已经初始化。

  2. 查询将按照已定义的顺序运行,但该过程将按照每个事件发生(而不是作为批处理,即如果有两个查询从inputStream消耗,则事件1进入时inputStream它转到查询1,然后查询2,然后只有事件2将被消耗..)。

  3. 请参阅以下代码段;

    /* Define the trigger to be used with initialization */
    define trigger triggerStream at 'start';
    
    /* Define streams */
    define stream inputStream (altitude int);
    define stream outputStream (theAltitude long, countAltitude int);
    
    /* Define table */
    define table counterTable (num long, count1 int, count2 int, tempNum int);
    
    /* Iterate and generate 100 events */
    from triggerStream[count() < 100]
    insert into triggerStream;
    
    /* Using above 100 events, initialize the event table */
    from triggerStream
    select count() as num, 0 as count1, 0 as count2, 0 as tempNum
    insert into counterTable;
    
    /* Perform the update logic here */
    from inputStream as i join counterTable as c
        on c.count1 < i.altitude
    select c.num, (c.count1 + 1) as count1, c.count2, altitude as tempNum
    insert into updateStream;
    
    from updateStream
    insert overwrite counterTable
        on counterTable.num == num;
    
    /* Join the table and get the updated results */
    from inputStream join counterTable as c
    select c.num as theAltitude, c.count1 as countAltitude
    insert into outputStream;
    

答案 1 :(得分:0)

表值可以按如下方式初始化。

@info(name='initialize table values')
from inputStream[count()==1]
select 1 as id, 0 as counter1, 0 as counter2, 0 as counter3
insert into counterTable;