siddhi window窗口學(xué)習(xí)探索

背景:

今天在線上測(cè)試時(shí)消費(fèi)了下堆積的數(shù)據(jù),結(jié)果發(fā)現(xiàn)siddhi的窗口數(shù)據(jù)好像不太對(duì)。于是測(cè)試下。使用了window.externalTimeBatch() 函數(shù)。siddhi沒有獲取窗口開始時(shí)間和結(jié)束時(shí)間的功能,于是想通過min(time),max(time)獲取,但是獲取后發(fā)現(xiàn)這兩個(gè)時(shí)間差居然遠(yuǎn)遠(yuǎn)大于窗口。于是在本地測(cè)試。

demo:
import io.siddhi.core.SiddhiAppRuntime;
import io.siddhi.core.SiddhiManager;
import io.siddhi.core.event.Event;
import io.siddhi.core.stream.input.InputHandler;
import io.siddhi.core.stream.output.StreamCallback;


public class HelloWorld {
    public static void main(String[] args) throws InterruptedException {
        SiddhiManager siddhiManager = new SiddhiManager();
        String siddhiApp =
                "define stream cseEventStream (id string,symbol string, price float, volume int,time long); " +
                        "from cseEventStream#window.externalTimeBatch(time,120 sec) select symbol,count(id) as count,min(time) as sTime,max(time) as eTime  group by symbol insert into outputStream;";
        ;
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

        InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        siddhiAppRuntime.start();
        siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
            @Override
            public void receive(Event[] events) {
                for (Event event : events) {
                    System.out.println(event);
                }
            }
        });
        inputHandler.send(new Object[]{"1", "Welcome1", 500f, 300, 1575011611080L}); //11-29 15:13:31
        inputHandler.send(new Object[]{"3", "Welcome1", 500f, 300, 1575011071000L}); //2019-11-29 15:04:31
        inputHandler.send(new Object[]{"4", "Welcome1", 500f, 800, 1575011791000L}); //2019-11-29 15:16:31
        siddhiAppRuntime.shutdown();
        siddhiManager.shutdown();
    }
}

結(jié)果:


image.png

這個(gè)結(jié)果居然統(tǒng)計(jì)了2個(gè),而且時(shí)間差也不止2分鐘??磥硎侵虚g亂序?qū)е碌摹?/p>

看了下官方文檔:


image.png

看來siddhi不支持亂序模式。這個(gè)窗口應(yīng)該是只判斷是不是小于結(jié)束時(shí)間,不判斷是不是大于窗口開始時(shí)間。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容