Search code examples
scalaesperepl

Optional values with Esper


Is there any support in Esper for properties with Optional values?

I'm building a POC with Esper, using Scala, and I have the EPL query working with non-optional values. I have a simple object that I'm using to test with:

case class EsperEvent(@BeanProperty id: Int, @BeanProperty eventtype: Int)

And can get my expected results with the following query:

select * from EsperEvent
 match_recognize (
   measures A as event1, B as event2
   pattern (A B)
   define
     A as A.eventtype = 2,
     B as B.eventtype = 3
 )

However, when I change my model to the following, I can't seem to get any output from Esper:

case class EsperEvent(@BeanProperty id: Int, @BeanProperty eventtype: Option[Int])

I've tried with the above query and also using dynamic properties as follows:

select * from EsperEvent
  match_recognize (
   measures A as event1, B as event2
   pattern (A B)
   define
     A as A.eventtype? = 2,
     B as B.eventtype? = 3
  )

Solution

  • The type of the property would be "java.util.Optional" if I'm not mistaken. You could use "A.eventtype.get()" which returns an Object and would need to be casted for example "cast(A.eventtype.get(), int)". It would be simpler if the event type is just boxed "Integer" for nullable values. EPL adheres to SQL92 standards and they sure don't have "optional".