Tim
Tim

Reputation: 437

Esper rule language: context nesting

I have the following two classes HeartRate with fields:

int heartrate;
String heartratesTimestamp;
String macAddress;

And Steps with fields:

int steps;
String stepsTimestamp;
String macAddress;

The rule I wrote fires when the number of steps is more then 100 in last 1 minute and heart rate is above 160.

EPStatement cepStatementRule7 = cepRule.createEPL("context PartitionByMac select * from "
            + "Steps.win:time(1 min) S, HeartRate.win:time(1 min) H "
            + "having (max(S.steps)-min(S.steps) > 100) and (H.heartrate > 160)");
    cepStatementRule7.addListener(new rule7Listener());

I would like to change this rule so that it is based on the context of the macAddress. So that the rule only considers the steps and heartrates with the same macAddress. I've written a context rule for the macAddress of steps and one for the macAddress of heartrate. They both work individually but when I try to nest them the rule won't fire anymore.

cepRule.createEPL("create context PartitionByMac 
context PartitionByMacSteps partition by macAddress from Steps, 
context PartitionByMacHeartRate partition by macAddress from HeartRate");

What am I doing wrong?

Upvotes: 0

Views: 75

Answers (1)

goodie
goodie

Reputation: 364

What you want is

create context PartitionByMac 
partition by macAddress from Steps, macAddress from HeartRate; 

This makes sure the same macaddress value lands in the same partition for analyzing Steps and Heartrate events.

The nested context behaves differently.

Upvotes: 1

Related Questions