Search code examples
complex-event-processingesper

How to use modules and distribute statements across multiple epl files?


After countless attempts and searching, how does one use modules in esper and distribute epl statements across multiple epl files?

An an example, there are two files:

// events.epl
module events;
    
    create schema OrderExample as (symbol string);

and

//example.epl
module tally;

    uses events;
    
    Select * from OrderExample;

Combining the modules via:

EPCompiler compiler = EPCompilerProvider.getCompiler();

List<File> files = new ArrayList<>();
files.add(new File("events.epl"));
files.add(new File("tally.epl"));

List<Module> modules = new ArrayList<>();

for (File file : files) {
        modules.add(compiler.readModule(file));
}


for (Module module : modules) {
        EPCompiled compiled = compiler.compile(module, compilerArguments);
        EPDeployment deployment = deploymentService.deploy(compiled);
 }

When combining the files together, the error is:

Exception in thread "main" com.espertech.esper.compiler.client.EPCompileException: Failed to resolve event type, named window or table by name 'OrderExample' [Select * from OrderExample]

Based off this documentation http://esper.espertech.com/release-8.8.0/reference-esper/html_single/#apicompiler-concepts


Solution

  • Each EPL module has its own namespace. Therefore one module can use the same names as another module and there is no conflict.

    For the case when an EPL module (say module B) relies on definitions that are made by another EPL module (say module A), you must define a visibility such as public visibility. See access modifiers.

    Also, the compiler that compiles module B must be able to see what module A provides. This is what the compiler path is about. See compiler path.

    So for example, you could have @public create schema OrderExample... and the @public tells the compiler that other modules can see the event type.

    And for the compiler path you could have arguments.getPath().add(runtime.getRuntimePath()); which adds all deployed event types to the compiler path.