I have the following query window in my application. I want an update on when the Employee event is coming the first time (a new Employee ) OR if there is any update for an existing Employee. My application is getting a lot of updates and I suspect the below Window is not keeping only the last two records in memory and due to that memory uses increase with time. Is there any way I can ensure that only last two records are available in Window?
@name('stmtUpdateEmployee') select * from Employee#groupwin(empId)#length(2)
where
prev(1, age) <> age OR
prev(1, dept) <> dept OR
prev(1, address) <> address OR
prev(1, empId) is null;
Your suspicion is correct! There will be more than the last two records in memory ... depending on the data, a lot more.
As mentioned in section Esper Reference 5.6.8, the
groupwin(empId)line in the select clause ...creates a separate data window per key value, and the query planner creates a hash index on
Employee, essentially resulting in holding onto all the employee events that have a uniqueempId.So this will grow with the number of unique employees ... there will be at least 2 * the number of unique employees events (since this is a length of 2, the latest employee event and the previous employee event are in memory.)