I'm using Esser EPL Online for getting deeper into CEP Engine Esper. Right now I'm struggling to define a EPL Statement that is true if an event happens before another event.
I want to use the "BEFORE"-Statement.
create schema A as (startts long, endts long) starttimestamp 'startts' endtimestamp 'endts'
create schema B as (startts long, endts long) starttimestamp 'startts' endtimestamp 'endts'
select * from A.std:lastevent() as a, B.std:lastevent() as b where a.before(b);
Everytime I press Submit, the following Error comes up:
Please check the EPL Module Text
Incorrect syntax near ''startts'' expecting an identifier but found QUOTED_STRING_LITERAL at line 1 column 61 [create schema A as (startts long, endts long) starttimestamp 'startts' endtimestamp 'endts' create schema B as (startts long, endts long) starttimestamp 'startts' endtimestamp 'endts' select * from A.std:lastevent() as a, B.std:lastevent() as b where a.before(b)]
Can anybody help me? Thank you very much. :)
Add a semicolon after each EPL statement.
create schema A as (startts long, endts long); // <-- Semicolon
Related
Let's say I have the following SQL statement:
SELECT 1 + myField + 2
If we want to reduce the expression at the parsing phase before sending it to SQL, we could turn it into:
SELECT 3 + myField
What is the name of the rule that allows this? Another example being:
SELECT myField * (1 + myField * 2 + 3)
Would turn into:
SELECT myField * (4 + (myField * 2) )
That's usually called "constant folding" (which should be a good search term) and it's easier to do as a transformation on the AST than trying to do it while you parse, precisely because of the reordering which is evident in your examples.
I am trying to write a Macro in IJ1 which would ask the user:
the number of event they want to record
to name those events
I started using Script Parameters as follow:
// # Integer (label="How many events do you want to record ?", min=1, max=50, value=1, persist=false) events
for (event=1; event<=events; event++) {
mLabel = "Name event number " + event + ":";
varname = "event" + event;
// # String (label="mLabel") varname
print(varname);
}
This doesn't work as it doesn't ask for the String. And even if it does, I guess it won't be very elegant as it would pop up a window to ask a Name n times (if 50, it'll be a nightmare...)
Ultimately, I want:
Box ask Number of Event
Answer is 3
Box ask Name of Event1, Event2, Event3
I would be really glad to have any help ! Thank you in advance !
When writing macros it is very useful to have the list of macros functions open https://imagej.net/developer/macro/functions.html
This should do the trick:
defaultname="event";
events=getNumber("How many events shall be run", 0);
for (event=1; event<=events; event++) {
eventname=getString("Please define name of event "+event+":", defaultname+event);
print(eventname);
}
I have a sqlite table with a mix of integer and float columns. I'm trying to get the max and min values of each column. For integer columns the following code works but I get a cast error when using the same code on float columns:
let numCats = query{for row in db do minBy row.NumCats}
For float columns I'm using the following code but it's slow.
let CatHight = query{for row in db do select row.CatHeight} |> Seq.toArray |> Array.max
I have 8 integer columns and 9 float columns and the behavior has been consistent across all columns so that's why I think it's an issue with the column type. But I'm new to F# and don't know anything so I'm hoping you can help me.
Thank you for taking the time to help, it's much appreciated.
SQLProvider version: 1.0.41
System.Data.SQLite.Core version: 1.0.104
The error is: System.InvalidCastException occurred in FSharp.Core.dll
Added Information
I created a new table with one column of type float. I inserted the values 2.2 and 4.2. Using SQLProvider and System.Data.SQLite.Core I connected queried the database using minBy or maxBy and I get the cast exception. If the column type is integer it works correctly.
More Added Information
Exception detail:
System.Exception was unhandled
Message: An unhandled exception of type 'System.Exception' occurred in >FSharp.Core.dll
Additional information: Unsupported execution expression value(FSharp.Data.Sql.Runtime.QueryImplementation+SqlQueryable1[FSharp.>Data.Sql.Common.SqlEntity]).Min(row => >Convert(Convert(row.GetColumn("X"))))`
Code that fails:
open FSharp.Data.Sql
[<Literal>]
let ConnectionString =
"Data Source=c:\MyDB.db;" +
"Version=3;foreign keys=true"
type Sql = SqlDataProvider<Common.DatabaseProviderTypes.SQLITE,
ConnectionString,
//ResolutionPath = resolutionPath,
CaseSensitivityChange = Common.CaseSensitivityChange.ORIGINAL>
let ctx = Sql.GetDataContext()
let Db = ctx.Main.Test
let x = query{for row in Db do minBy row.X}
printfn "x: %A" x
Update 2/1/17
Another user was able to reproduce the issue so I filed an Issue with SQLProvider. I'm now looking at workarounds and while the following code works and is fast, I know there's a better way to do it - I just can't find the correct way. If somebody answers with better code I'll accept that answer. Thanks again for all the help.
let x = query {for row in db do
sortBy row.Column
take 1
select row.Column } |> Seq.toArray |> Array.min
This is my workaround that #s952163 and good people in the SO f# chat room helped me with. Thanks again to everyone who helped.
let x = query {for row in db do
sortBy row.Column
take 1
select row.Column } |> Seq.head
You need to coerce the output column to int or float (whichever you need or is giving trouble to you). You also need to take care in case any of your columns are nullable. The example below will coerce the column to float first (to take care of being nullable), then convert it to int, and finally get the minimum:
let x = query { for row in MYTABLE do
minBy (int (float row.MYCOLUMN))}
You might want to change the order of course, or just say float Mycolumn.
Update:
With Sqlite it indeed causes an error. You might want to do query { ... } |> Seq.minBy to extract the smallest number.
I'm having a weird problem, I created a custom SQL function based on this suggestion. I have a model Route with a controller action create that calls this method on the model
def get_route(startx, starty, endx, endy)
query = "SELECT seq, cost, slope::double precision, designacao::character varying(192), length::double precision," +
"ST_AsGeoJSON(geom) FROM pgr_dijkstra('" +
"SELECT gid AS id," +
"source::integer," +
"target::integer," +
"length AS cost " +
"FROM ways WHERE CAST(classif as int) <> 2'," +
"get_nearest_vertex_to_lon_lat(CAST(#{startx} as float) , CAST(#{starty} as float)), " +
"get_nearest_vertex_to_lon_lat(CAST(#{endx} as float), CAST(#{endy} as float)), false, false) a LEFT JOIN ways b ON (a.id2 = b.gid);"
results = ActiveRecord::Base.connection.execute(query)
return results
end
This works on development but doesn't work on production, it gives an
PG::UndefinedFunction: ERROR: function get_nearest_vertex_to_lon_lat(double precision, double precision) does not exist
and also
ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR: function get_nearest_vertex_to_lon_lat(double precision, double precision) does not exist
The weird part is that I execute this query on postgres and it works.
As it turns out, despite my config database.yml for production, I was unaware that Heroku creates its own production database, so obviously didn't know any custom sql function, or even tables.
For future reference, if you're deploying to heroku and you're using a remote database you have to do this first and then set your own DATABASE_URL
I was trying to implement a Deedle solution for the little challenge from #migueldeicaza to achieve in F# what was done in http://t.co/4YFXk8PQaU with python and R. The csv source data is available from the link.
The start is simple but now, while trying to order based upon a column series of float values I'm struggling to understand the syntax for the IndexRows type annotation.
#I "../packages/FSharp.Charting.0.90.5"
#I "../packages/Deedle.0.9.12"
#load "FSharp.Charting.fsx"
#load "Deedle.fsx"
open System
open Deedle
open FSharp.Charting
let bodyCountData = Frame.ReadCsv(__SOURCE_DIRECTORY__ + "/film_death_counts.csv")
bodyCountData?DeathsPerMinute <- bodyCountData?Body_Count / bodyCountData?Length_Minutes
// select top 3 rows based upon default ordinal indexer
bodyCountData.Rows.[0..3]
// create a new frame indexed and ordered by descending number of screen deaths per minute
let bodyCountDataOrdered =
bodyCountData
|> Frame.indexRows <float>"DeathsPerMinute" // uh oh error here - I'm confused
And because I can't figure that syntax out... various messages like:
Error 1 The type '('a -> Frame<'c,Frame<int,string>>)' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface. See also c:\wd\RPythonFSharpDFChallenge\RPythonFSharpDFChallenge\EvilMovieQuery.fsx(18,4)-(19,22). c:\wd\RPythonFSharpDFChallenge\RPythonFSharpDFChallenge\EvilMovieQuery.fsx 19 8 RPythonFSharpDFChallenge
Error 2 Type mismatch. Expecting a
'a -> Frame<'c,Frame<int,string>>
but given a
'a -> float
The type 'Frame<'a,Frame<int,string>>' does not match the type 'float' c:\wd\RPythonFSharpDFChallenge\RPythonFSharpDFChallenge\EvilMovieQuery.fsx 19 25 RPythonFSharpDFChallenge
Error 3 This expression was expected to have type
bool
but here has type
string c:\wd\RPythonFSharpDFChallenge\RPythonFSharpDFChallenge\EvilMovieQuery.fsx 19 31 RPythonFSharpDFChallenge
Edit: Just thinking about this... indexing on a measured float is a silly thing to do anyway - duplicates and missing values in real world data. So, I wonder what a more sensible approach to this would be. I still need to find the 25 max values... Maybe I can work this out for myself...
With Deedle 1.0, you can sort on an arbitrary column.
See: http://bluemountaincapital.github.io/Deedle/reference/deedle-framemodule.html#section7