Question

I'm working with Esper + Mule and I am trying to define a POJO and an Event, but after reading the documentation of Espero I haven't found what I really need.

My event, represented by a POJO, has a property like this:

List<String> Words;

What I would like to do is use the keyword IN to compare it with another list of words, so the pattern would look like this:

... Words in ('word1', 'word2', 'word3) ...

But I get this error:

Collection or array comparison is not allowed for the IN, ANY, SOME or ALL keywords

Is there any way to achieve this?

Thank you very much

Was it helpful?

Solution

One way is to create a method to do what you want, register that method with esper, and reference that method from your EPL statement:

Create helper class (for this example, I use EsperUtils.java):

package my.package;

class EsperUtils {
  public static boolean contains(List<String> list1, List<String> list2) {

    // Check for list1 and list2 to contain same word
    for (String s1 : list1) {
      for (String s2 : list2) {
        if (s1.equals(s2)) return true;
      }
    }
    return false;
  }
}

Register method with esper in aem.esper.config.xml:

<plugin-singlerow-function name="contains" function-class="my.package.EsperUtils" function-method="contains" />

Use the helper method in your EPL:

select * from myEvent where contains(Words,AnotherListOfWords)

You could also add the helper method to your event POJO instead of a helper class.

OTHER TIPS

You'd want to look at enumeration methods, see http://esper.codehaus.org/esper-4.9.0/doc/reference/en-US/html_single/index.html#enumerationreference It seems that "intersect" and "countOf" in combination would suit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top