我有一些相关的问题:
其次,初始化完成后,我想更新此表。查询1执行完成后,如何在同一执行计划中执行query2?
要完成,我有一个'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;
答案 0 :(得分:0)
如果要在每次部署执行计划时进行初始化,则应使用内存事件表(如下所示)。否则,您只需使用RDBMS event table,它已经初始化。
查询将按照已定义的顺序运行,但该过程将按照每个事件发生(而不是作为批处理,即如果有两个查询从inputStream
消耗,则事件1进入时inputStream
它转到查询1,然后查询2,然后只有事件2将被消耗..)。
请参阅以下代码段;
/* 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;