我有一个非实时的Esper配置,我提供了一个从文件中读取的流。我正在尝试创建一个表达式来计算整个流的统计量,并在最后输出一个值。例如,Esper具有强制视图每X秒输出一次的语义,但当您知道没有更多事件需要提供时,是否有一个语义用于要求视图或引擎“刷新”输出。
答案 0 :(得分:8)
事实证明,至少有一种方法是使用带有变量触发器的输出子句。
表达式为:
select count(*) as totalCount from events output last when OutputSummary = true
OutputSummary变量将初始化为:
epConfiguration.addVariable("OutputSummary", Boolean.class, "false");
当您准备好刷新时,将变量设置为true,如下所示:
epRuntime.setVariableValue("OutputSummary", true);
long currentTime = epService.getEPRuntime().getCurrentTime();
epRuntime.sendEvent(new CurrentTimeEvent(currentTime));
有必要发送另一个时间事件来强制表达式进行评估。
答案 1 :(得分:0)
当输出需要每60秒时,表达式为:
select emplyee_id from employees output snapshot every 60 sec
当输出每10000个事件需要时,表达式为:
select emplyee_id from employees output snapshot every 10000 events