简体   繁体   中英

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.

Lets say we have value1 and value2 in input stream.

  • host:A, Value1:1, value2:10
  • host:A, Value1:2, value2:20
  • host:A, Value1:3, value2:30
  • host:A, Value1:4, value2:40
  • host:A, Value1:5, value2: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.

But what it does is, it applies SUM functions on all 5 rows after grouping but the custom function is invoked row by row. 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.

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

/**
     * 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 is supposed to be used for such scenarios and functions are for individual rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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