Skip to content
Advertisement

Esper: group by value in a named window and use this grouped value to determine the output id

I want to create a named window that takes the last 20 seconds of speed settings (1-10) and power outputs (float). Then I want to query this to get the average power per speed setting (from 1-10). For each speed setting I need to specify a specific output id. I tried to do this using an expression to convert the speed into this output id, but no matter which way I have done it, I get the error “expression requires stream name as a parameter”.

Can anyone point out the correct expression + how to use the expression in order to get my desired output?

If you can point out a better way to do it then that is great also. I am an esper newbie + don’t know Java and I am running these scripts on a server with a CEP stack which I have no idea what’s going on under the hood so I am finding it very hard to troubleshoot!

CREATE expression getOutput {
   speed =>
      when speed = 1 then 4000
      when speed = 2 then 5000
      ....
};

CREATE window Power.win:time(20 sec) as (power double, speed int);

INSERT into PortPower
SELECT 
    powerEvent.value as power,
    cast(speedSetting.value, int) as speed
FROM 
    Event(id = 1000).std:lastevent() as powerEvent,
    Event(id = 2000).std:lastevent() as speedEvent;
    

INSERT into Event
SELECT
    getOutput(powerEvent.speed) as id,
    avg(PowerEvent.power) as value
FROM
    Power as PowerEvent
GROUP BY
   PowerEvent.speed
HAVING
   count(PowerEvent.speed) > 0;

Advertisement

Answer

“expression requires stream name as a parameter” is I think an older version error message, a version of EPL that only allowed streams names for expression parameters. Try and go with the current version that doesn’t have this limitation.

Your EPL has more going on than was asked in the question. When asking a question its better to stay focused on just and only that which is relevant to the specific question. Please edit the question and remove all unrelated stuff. Asking one clear minimal question per post helps me save time.

Since you insist on the old version, you can use just insert into like so:

insert into ResultStream select ... from ....

select ..., 
  case when speed = 1 then 4000 .... end as speedMappedToWhatever 
from ResultStream
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement