Search code examples
javaparametersruntimeesper

Pass parameter to ESPER EPL query?


I am new to esper epl query.I want to know is it possible to change EPL query in run time.It means I have a form which can use to change the time length,number of records in ESPER.It is simply like this,increase the time length in epl query,number of records in event.Likewise i want to change parameter in pragmatically.I want to know is this possible and if yes give me some hint to start. Thanks


Solution

  • Depending on your actual requirement you can use Variables. From Esper Docs:

    In addition to creating a variable via the create variable syntax, the runtime and engine configuration API also allows adding variables. The next code snippet illustrates the use of the runtime configuration API to create a string-typed variable:

    epService.getEPAdministrator().getConfiguration().addVariable("myVar", String.class, "init value");
    

    Then you can use variables in your queries. For instance (again from Esper docs):

    The next statement assumes that a variable named 'var_threshold' was created to hold a total price threshold value. The statement outputs an event when the total price for a symbol is greater then the current threshold value:

     select symbol, sum(price) 
       from TickEvent  group by symbol having
       sum(price) > var_threshold
    

    So if you exactly know what you want to parametrize, then you can make your queries more dynamic.