I am trying to implement a sample project in Siddhi. There is an input event stream with one attribute height
. I want to write a sequence
query that gives a callback when there are three successive events with same height.
I have referred to this and this blog but I am not able to get the syntax right. I am getting SiddhiParserException
when trying to run the sequence query.
this is the corresponding pattern query which works fine.
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 ;";
Below is how I am writing the sequence query to get two consecutive equal heights but I am not able to get it right.
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 ;";
Adding Error logs:
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$1.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)
Any help is appreciated.
I managed to solve the issue. It was the missing space at the end of string segments. Notice the space at the end of 5th and 6th line after "]" and "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 ;";