WSO2流处理器:Siddhi App计算总和

时间:2019-09-26 14:17:57

标签: wso2 wso2-das wso2sp

我正在使用流处理器4.3.0。我碰到过一种情况,我正在使用siddhiapp将一些数据馈入到rdbms表中。使用siddiapp,我在RDBMS表中输入数据,如下所示

enter image description here

现在,我正在使用另一个SiddhiApp来检索数据,但我想尝试以如下方式获取数据

enter image description here

当公共列缩小为一行时,现在将具有计数的列求和以得到所有计数的最终总和。

请问有人可以指导我如何进行此处

预先感谢

这是获取总金额的应用程序

    @App:name("IncomingStream3")
    @App:description("Description of the plan")

    -- Please refer to https://docs.wso2.com/display/SP400/Quick+Start+Guide on getting started with SP editor. 

    --@store(type = 'rdbms', datasource = 'APIM_ANALYTICS_DB')
    --@purge(enable='false', interval='60 min', @retentionPeriod(sec='1 day', min='72 hours', hours='90 days', days='1 year', months='2 years', years='3 years'))

    define stream  TempStatsStream (AGG_TIMESTAMP long, AGG_EVENT_TIMESTAMP long, apiName string, apiVersion string, apiResourcePath string,apiCreator string,username string, applicationConsumerKey string, AGG_LAST_EVENT_TIMESTAMP long, applicationName string, dateTime string, AGG_COUNT int);

    define aggregation StatsToCal

    from TempStatsStream
    select apiName, apiVersion, apiResourcePath, apiCreator, username, applicationName, 
    applicationConsumerKey, SUM (AGG_COUNT) as totalRequestCount, dateTime

    group by apiName, apiVersion, apiResourcePath, username, applicationConsumerKey
    aggregate by dateTime every days;

我在这里所做的唯一更改不是从DB表中获取值,而是将其视为流(因为我认为聚合只能针对Stream进行)。

1 个答案:

答案 0 :(得分:0)

好像您必须按API,Name1,Name2和ID分组?您可以使用类似于SQL group by的group by

from TriggerStream join APITable
select APIName, Name1, Name2, ID, sum(Count) as totalCount
group by API, Name1, Name2, ID
insert into OutputStream;