在 Siddhi 中编写序列查询

Writing a sequence query in Siddhi

我正在尝试在 Siddhi 中实现一个示例项目。有一个具有一个属性 height 的输入事件流。我想写一个 sequence 查询,当三个连续的事件具有相同的高度时,它会给出一个回调。 我参考了 this and this 博客,但语法不正确。我在尝试 运行 序列查询时得到 SiddhiParserException

这是对应的模式查询,效果很好。

executionPlan = "" +
                "define stream cseEventStream (height int); " +
                "" +
                "@info(name = 'query1') " +
                "from every e1 =  cseEventStream " +
                "-> e2 = cseEventStream[e1.height == e2.height]" +
                "-> e3 = cseEventStream[e2.height == e3.height] "+
                "select e1.height as height1, e2.height as height2, e3.height as height3  " + 
                "insert into outputStream ;";

下面是我如何编写序列查询来获得两个连续的相等高度,但我无法做到正确。

executionPlan = "" +
                "define stream cseEventStream (height int); " +
                "" +
                "@info(name = 'query1') " +
                "from every e1 =  cseEventStream, e2 = cseEventStream[e1.height == height]" +
                "select e1.height as height1, e2.height as height2" + 
                "insert into outputStream ;";

添加错误日志:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.mojo.exec.ExecJavaMojo.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.wso2.siddhi.query.compiler.exception.SiddhiParserException: You have an error in your SiddhiQL at line 1:195, extraneous input 'into' expecting {',', GROUP, HAVING, INSERT, DELETE, UPDATE, RETURN, OUTPUT}
at org.wso2.siddhi.query.compiler.internal.SiddhiErrorListener.syntaxError(SiddhiErrorListener.java:36)
at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:65)
at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:566)
at org.antlr.v4.runtime.DefaultErrorStrategy.reportUnwantedToken(DefaultErrorStrategy.java:375)
at org.antlr.v4.runtime.DefaultErrorStrategy.sync(DefaultErrorStrategy.java:273)
at org.wso2.siddhi.query.compiler.SiddhiQLParser.query_section(SiddhiQLParser.java:3702)
at org.wso2.siddhi.query.compiler.SiddhiQLParser.query(SiddhiQLParser.java:1903)
at org.wso2.siddhi.query.compiler.SiddhiQLParser.execution_element(SiddhiQLParser.java:619)
at org.wso2.siddhi.query.compiler.SiddhiQLParser.execution_plan(SiddhiQLParser.java:550)
at org.wso2.siddhi.query.compiler.SiddhiQLParser.parse(SiddhiQLParser.java:152)
at org.wso2.siddhi.query.compiler.SiddhiCompiler.parse(SiddhiCompiler.java:63)
at org.wso2.siddhi.core.SiddhiManager.createExecutionPlanRuntime(SiddhiManager.java:61)
at mainpkg.DriverClass.initiateExecutionPlan(DriverClass.java:54)
at mainpkg.DriverClass.main(DriverClass.java:37)

感谢任何帮助。

我设法解决了这个问题。它是字符串段末尾缺少的 space。注意第 5 行和第 6 行末尾的 space,在“]”和 "height2"

之后
executionPlan = "" +
                "define stream cseEventStream (height int); " +
                "" +
                "@info(name = 'query1') " +
                "from every e1 =  cseEventStream, e2 = cseEventStream[e1.height == height] " +
                "select e1.height as height1, e2.height as height2 " + 
                "insert into outputStream ;";