在Esper中强制输出
问题描述:
我有一个非实时Esper配置,其中我提供了一个从文件中读取的流。我试图创建一个表达式来计算整个流的统计量并在最后输出一个值。例如,Esper具有强制视图每隔X秒输出一次的语义,但是在知道没有更多事件需要输入时,请求视图或引擎“刷新”输出的语义是否有语义。在Esper中强制输出
答
原来,至少有一种方法是使用带有变量触发器的输出子句。
的表达应该是:
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));
有必要发送另一个时间事件来强制表达式进行评估。
答
当输出需要在每60秒,则表达式将是:
select emplyee_id from employees output snapshot every 60 sec
并且当所述输出需要在每10000个事件,则表达式将是:
select emplyee_id from employees output snapshot every 10000 events