简体   繁体   English

wso2 cep Siddhiql 合并来自 2 个流的数据

[英]wso2 cep Siddhiql merge data from 2 streams

I want to do statistics and the statistics are in a percentage.我想做统计,统计是百分比。

I have a query that tells me the number of events coming from one stream that contains several values ['R','B','A','C'].我有一个查询,它告诉我来自一个包含多个值 ['R','B','A','C'] 的流的事件数。 And i want to count how many Bs there are in stream1 in percentage.我想以百分比计算stream1中有多少个B。

Number of events in stream1流 1 中的事件数

@info(name='Query 1')
from stream1
select count() as numEvents
insert into event_num;

Number of events that are of type B B 类事件的数量

@info(name='Query 2')
from stream1[value == 'B']
select count() as numBs
insert into b_num;

Percentage count:百分比计数:

@info(name='Query 3')
from every e1=event_num,e2=b_num
select (e2.numBs*100)/e1.numEvents as bpercent
insert into b_percent;

if there is a value that is not B, then query 3 will not increment the numEvents and recalculate the percentage.如果存在不是 B 的值,则查询 3 不会增加 numEvents 并重新计算百分比。 Meaning that the Bs percentage will only be calculated if a B comes in. Which is not what i want.这意味着只有在 B 进来时才会计算 Bs 百分比。这不是我想要的。 I want B percentage to decrease if a different value comes in. and increase if B comes in.如果输入不同的值,我希望 B 百分比减少。如果 B 输入,则增加。

How can I make the Query3 in a way that whether event_num or whether v_num receives a new event calculates de percentage?如何使 Query3 以 event_num 或 v_num 是否接收新事件计算百分比的方式进行?

How about following execution plan:下面的执行计划怎么样:

@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;

Here,这里,

  • for each and every event, numAll counter will be incremented.对于每个事件, numAll计数器都会增加。
  • if a B -valued event comes, then numB counter will be counted.如果B值事件到来,则将计算numB计数器。

  • percentage calculation will be done for each and every event arrival (regardless of the value )将针对每个事件到达进行百分比计算(无论value如何)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM