我想做统计,统计数据是百分比。
我有一个查询,告诉我来自一个包含多个值的流的事件数量[' R',' B',' A', ' C&#39]。我想计算stream1中有多少Bs百分比。
stream1中的事件数
@info(name='Query 1')
from stream1
select count() as numEvents
insert into event_num;
B类型的事件数
@info(name='Query 2')
from stream1[value == 'B']
select count() as numBs
insert into b_num;
百分比计数:
@info(name='Query 3')
from every e1=event_num,e2=b_num
select (e2.numBs*100)/e1.numEvents as bpercent
insert into b_percent;
如果存在不是B的值,则查询3将不会增加numEvents并重新计算百分比。这意味着Bs百分比仅在B进入时计算。这不是我想要的。如果有不同的值,我希望B百分比减少。如果B进来,我希望增加。
如何以event_num或v_num是否收到新事件计算de百分比的方式生成Query3?
答案 0 :(得分:1)
如何遵循执行计划:
@IndexBy('dummyId')
define table counterTable (dummyId int, numBs long, numAll long);
define stream stream1 (value string);
@info(name='counting bValues')
from stream1[value == 'B']
select 1 as dummyId, count() as numBs
update counterTable
on counterTable.dummyId == dummyId;
@info(name='counting allValues')
from stream1
select 1 as dummyId, count() as numAll
update counterTable
on counterTable.dummyId == dummyId;
@info(name='processing allValues')
from stream1 JOIN counterTable
select (counterTable.numBs * 100) / counterTable.numAll as percentage
insert into statStream;
下面,
numAll
计数器将递增。如果有B
值事件发生,则numB
计数器将被计算在内。
将对每个活动到达进行百分比计算(无论value
)