I would like to fire a pattern with the following syntax.
EPStatement raiseStmt = cepAdm.createEPL("[1] Event");
But i am getting the following exception
Exception in thread "main" com.espertech.esper.client.EPStatementSyntaxException: Incorrect syntax near '[' [[1] Event]
at com.espertech.esper.epl.parse.ExceptionConvertor.convertStatement(ExceptionConvertor.java:47)
at com.espertech.esper.epl.parse.ParseHelper.parse(ParseHelper.java:112)
at com.espertech.esper.core.service.EPAdministratorHelper.compileEPL(EPAdministratorHelper.java:99)
at com.espertech.esper.core.service.EPAdministratorHelper.compileEPL(EPAdministratorHelper.java:71)
at com.espertech.esper.core.service.EPAdministratorImpl.createEPLStmt(EPAdministratorImpl.java:116)
at com.espertech.esper.core.service.EPAdministratorImpl.createEPL(EPAdministratorImpl.java:66)
at exampleMain.main(exampleMain.java:202)
The "admin.createEPL" method takes an EPL statement and not just a pattern. For example "select * from pattern[[1] Event]".
This is equivalent to: admin.createPattern("[1] Event")
Related
Hi i am trying to learn Lua, I was playing around with the language and I come accrosed this code block
for i = 1, 4, 1
do
if(i == 2) then
break
undefinedFunction("print 1")
end
print("print 2")
end
which is fine for the interpreter and did nothing for the undefined function. On the other hand if we make this code block like that
for i = 1, 4, 1
do
if(i == 2) then
break
1
end
print("Hello World asdasdsad asdasdas")
end
which the lua interpreter throws error unexpected sign '1'.
So i thought that Lua interpreter fines with undefined functions and just ignore them but if i code like that
for i = 1, 4, 1
do
if(i == 2) then
break
end
undefinedFunction("argument 1")
print("print 1")
end
now Lua interpreter gives error. Why there is an inconsistency?
The difference here is "syntax error" vs "runtime error".
The second snippet has a syntax error: A single literal (such as a number 1 or a string "foo") is not a valid statement.
A file needs to be free of syntax errors before Lua can even begin to run it, which is why the second snippet will fail regardless of where you put the line with the 1.
The third snippet has a runtime error: The file syntax is perfectly fine and Lua can start interpreting it. Only when it reaches the offending line will the VM realize that undefinedFunction == nil and that it can't use that as a function.
Contrast to the first snippet, where:
there is no syntax error
the line with a runtime error is "hidden" behind a break and will never be reached, thereby never triggering the error
And the break is nothing special here, a simple if can show the same behaviour:
Syntax error:
if true then
1
end
Runtime error:
if true then
undefined()
end
No error:
if false then
undefined() -- This line is never reached, and will not cause an error
end
First of all: Let's clean your code up a bit.
for i = 1, 4 do
if i == 2 then
break
undefinedFunction("print 1")
end
print("print 2")
end
This code is not fine in Lua 5.1: In Lua 5.1, break must be the last statement in a block - that is, writing "dead code" after a break is syntactically not allowed and raises a syntax error. With the introduction of a powerful goto, later Lua versions started allowing code after a break as it may be alive if a goto is used.
Still, the call to undefinedFunction("print 1") is never executed, and as such never gets to throw a run-time error.
Now let's take a look at your second snippet, again cleaned up:
for i = 1, 4 do
if i == 2 then
break
1
end
print("print 2")
end
This throws a syntax error because the number 1 is an expression, not a statement. break is a statement. A block is a list of statements. Lua expects either the end of the block or another statement, you give it an expression - syntax error.
Now to the third snippet:
for i = 1, 4 do
if i == 2 then
break
end
undefinedFunction("argument 1")
print("print 2")
end
throws a runtime error because the global variable undefinedFunction - the same as _G["undefinedFunction"] is undefined (nil) - and you are trying to call a nil value.
I am very new to using groovy. Especially when it comes to Jenkins+Groovy+Pipelines.
I have a string variable that can change from time to time and want to apply a regex to accomodate the 2 or 3 possible results the string may return.
In my groovy code I have:
r = "Some text that will always end in either running, stopped, starting."
def regex = ~/(.*)running(.*)/
assert regex.matches(r)
But I receive an error in the jenkins output:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.regex.Pattern.matches() is applicable for argument types: (java.lang.String)
UPDATE:
I was able to create a pretty nifty jenking groovy while loop in a pipeline job i am creating to wait for a remote process using the regex info here and a tip in a different post (How do I iterate over all bytes in an inputStream using Groovy, given that it lacks a do-while statement?).
while({
def r = sh returnStdout: true, script: 'ssh "Insert your remote ssh command that returns text'
println "Process still running. Waiting on Stop"
println "Status returned: $r"
r =~ /running|starting|partial/
}());
Straight-forward would be:
String r = "Some text that will always end in either running, stopped, starting."
assert r =~ /(.*)running(.*)/
If you are only using this regex here you can try the following:
r = "Some text that will always end in either running, stopped, starting."
assert r ==~ /(.*)(running|stopped|starting)\.?$/, "String should end with either running, started or stopped"
Explanation:
(.*) - matches anything
(running|stopped|starting) - matches either running, stopped or starting
\.? - optionally end with a dot expect zero or one occurrence of a dot, but you need to escape it, because the dot is a regex special character
$ - end of the line, so nothing should come after
the ==~ operator is the groovy binary match operator. This will return true if it matches, else false
See this example on regex 101
matches does not receive String.
Try
Pattern.compile("your-regex").matcher("string-to-check").find()
I'm not being able to catch what I'm doing wrong. I'm able to run the query on neo4j console with hardcoded values.
I'm trying to do the following query on my repository class:
#Query("START user=node({0}) \n" +
"MATCH (anotherUser) \n" +
"WHERE NOT (anotherUser<-[:MATCHES]-user) AND NOT user = anotherUser \n" +
"RETURN anotherUser")
Iterable<User> findMatchesForUser(User user);
The result of the query should be all User nodes that doesn't have a :MATCHES edge between the user I'm passing as an argument.
I get the following exception:
SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement START user=node({0})
MATCH (anotherUser)
WHERE NOT (anotherUser<-[:MATCHES]-user) AND NOT user = anotherUser
RETURN anotherUser; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement START user=node({0})
MATCH (anotherUser)
WHERE NOT (anotherUser<-[:MATCHES]-user) AND NOT user = anotherUser
RETURN anotherUser; nested exception is `,' expected but `W' found
I also believe it's inline with the example here. Any tip would be appreciated.
I was able to get the same result with the following query:
#Query("START n=node({0}), a=node(*) \n" +
"MATCH (n)-[r?:MATCHES]->(a) \n" +
"WHERE has(a.__type__) AND r IS NULL AND a <> n \n" +
"RETURN a");
Iterable<User> findMatchesForUser(User user);
For a reason I still can't really understand, I had to add the has(a.type) for my query to work, or it would throw "Could not write JSON: 'type' property not found for NodeImpl#0" when trying to serialize it.
I want to exit execution of Lua script on some condition .
Example :
content = get_content()
if not content then
-- ( Here i want some kind of exit function )
next_content = get_content()
--example there can lot of further checks
Here I want that if I am not getting content my script suppose to terminate is should not go to check to next.
Use os.exit() or just return from some "main" function if your script is embedded.
os.exit()
kill process by sending a signal
do return end
stop execution
The two methods are not equal if you want to write and execute some luacode in the interpreter after stopping the execution by launching your program using the -i flag.
th -i main.lua
extract from the lua api doc :
For syntactic reasons, a break or return can appear only as the last statement of a block (in other words, as the last statement in your chunk or just before an end, an else, or an until). For instance, in the next example, break is the last statement of the then block.
local i = 1
while a[i] do
if a[i] == v then break end
i = i + 1
end
Usually, these are the places where we use these statements, because any other statement following them is unreachable. Sometimes, however, it may be useful to write a return (or a break) in the middle of a block; for instance, if you are debugging a function and want to avoid its execution. In such cases, you can use an explicit do block around the statement:
function foo ()
return --<< SYNTAX ERROR
-- `return' is the last statement in the next block
do return end -- OK
... -- statements not reached
end
In lua 5.2.0-beta-rc1+, you can add a label at the end of your code called ::exit:: or something of the like, and then whenever you need to exit the program just call it like this:
goto exit
Depending if it errors are raised or not, pcall(function) may return:
Success: true and the return value[s] of the function.
Failure: false and the error.
In my case I'm calling a function to return a table, so in case of no errors I will get my data from the second return value, and in case of error I will print manage the error.
How can I do it with assert?
At first I wrote this:
local ret, data = pcall(the_function)
assert(ret, "Error: "..data)
-- use data from here on.
The problem is that the assert message is evaluated even in case of success, so when the call succeeds Lua complains about concatenating a string with a table.
This problem is due to the fact that I want to use assert and cite the error, but avoiding using something like if not ret then assert(false, "...") end.
Try this:
local ret, data = assert(pcall(the_function))
If you don't need to alter the error message from pcall lhf's suggestion is best.
Otherwise a solution is:
local ret, data = pcall( the_function )
assert( ret, type( data ) == 'string' and "Error: " .. data )
or this one, which is a cleaner approach:
local ret, data = pcall( the_function )
if not ret then error( "Error: " .. data ) end
this latter avoids completely to evaluate the error message expression if pcall doesn't give an error.