简体   繁体   English

WSO2 CEP自定义功能不能用作聚合功能

[英]WSO2 CEP custom function doesn't work as aggregate function

WSO2 CEP custom function doesn't work as aggregate function, instead it operates on each row of data. WSO2 CEP自定义函数不能用作聚合函数,而是对每行数据进行操作。

Lets say we have value1 and value2 in input stream. 可以说输入流中有value1和value2。

  • host:A, Value1:1, value2:10 主机:A,值1:1,值2:10
  • host:A, Value1:2, value2:20 主机:A,值1:2,值2:20
  • host:A, Value1:3, value2:30 主机:A,值1:3,值2:30
  • host:A, Value1:4, value2:40 主机:A,值1:4,值2:40
  • host:A, Value1:5, value2:50 主机:A,值1:5,值2:50

Now I have done the time batching and grouping by host. 现在,我已经按主机完成了时间批处理和分组。 And have written a custom function which finds the MEDIAN, and also used inbuilt function SUM. 并且编写了一个自定义函数来查找MEDIAN,并且还使用了内置函数SUM。

But what it does is, it applies SUM functions on all 5 rows after grouping but the custom function is invoked row by row. 但是它的作用是,在分组后将SUM函数应用于所有5行,但是自定义函数逐行调用。 The process method in the custom function class was getting called row by row. 自定义函数类中的处理方法被逐行调用。 Hence SUM returns 15 but my MEDIAN function gives output as 50 which is just last value2. 因此,SUM返回15,但是我的MEDIAN函数给出的输出为50,这只是最后一个值2。

Execution Plan Query 执行计划查询

from inputStream#window.timeBatch(10 sec)
select value1 as value1, value2 as value2, sum(value1) as sumOfValue1, custom:median(value2) as medianOfValue2 group by host
insert into outputStream;

Custom Function Java Class Snippet 自定义函数Java类代码段

/**
     * Method called when sending events to process
     *
     * @param obj
     * @return
     */
    @Override
    protected Object process(Object obj) {

Can't we have a custom aggregate function, or if custom function is only supposed to be executed on row by row basis ??? 我们不能有一个自定义的聚合函数,或者自定义函数只能按行执行吗?

You can solve this by writing a custom OutputAttributeAggregator instead of a custom function. 您可以通过编写自定义OutputAttributeAggregator而不是自定义函数来解决此问题。 OutputAttributeAggregator is supposed to be used for such scenarios and functions are for individual rows. 应该将OutputAttributeAggregator用于此类情况,并且函数用于单个行。

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

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