]
Mario Fusco resolved DROOLS-591.
--------------------------------
Resolution: Rejected
"not" and "accumulate" ordering LHS yield
different counting
------------------------------------------------------------
Key: DROOLS-591
URL:
https://issues.jboss.org/browse/DROOLS-591
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Affects Versions: 6.1.0.Final
Reporter: Matteo Mortari
Assignee: Mario Fusco
Ref. original post in Drools-Usage
https://groups.google.com/d/msg/drools-usage/ETkH7gn3YwY/Fc46KqqkN9QJ
h5. excerpt of original post
I'm experiencing a very weird behavior of using "not" and
"accumulate", their ordering in LHS yield different counting results. I can
provide privately a reproducer because this happens only when several rules are deployed -
the other rules do NOT interact over the same objects in memory, except from queries.
The example knowledge base below, the goal is to detect spikes in temperature (integers)
over the last 5m, and raise/clear an Alert accordingly. The unit test prove that when
either of the rules "Trending Alert" or "Trending Clear" fires, the
content of $myList if compared to the $myList coming from the third rule, is the SAME,
because indeed just collecting over the same over window:time(5m)
However, here is the odd behavior, when I also deploy the full kb:
* If I leave "Trending Alert" this way, the content of $myList when the rule
fire, actually extend beyond the 5m sliding window, in fact keeping track of 20m, 30m old
samples, therefore yielding wrong results
* If I reorder "Trending Alert" LHS to have the not Alert ( condition ==
"TEMPERATURE_TRENDING") to appear before the accumulate, the content of $myList
when the rule fire is correct.
* If I leave "Trending Alert" this way, and I remove other .drl files, the
content of $myList when the rule fire is correct.
Thanks
{code}
rule "Trending Alert"
no-loop
when
accumulate( $cc : AirSurveyTemp ($temp : TheTemp ) over window:time(5m) ;
$myList : collectList($cc),
$number : count($cc),
$min : min($temp),
$max : max($temp) ;
$max-$min > 10 )
$oWhere : Measurement( id == "Inhabited area", val == "False" )
not Alert ( condition == "TEMPERATURE_TRENDING")
then
Alert a = new Alert();
a.setCondition("TEMPERATURE_TRENDING");
System.out.println("++ Temperature Trending - " + a.getCondition() + " -
Number of Object: " + $number + " - Min Value = " + $min + " - Max
Value: " + $max );
insert(a);
alert.clear();
alert.addAll($myList);
end
rule "Trending Clear"
no-loop
when
$a : Alert(condition == "TEMPERATURE_TRENDING")
accumulate( $cc : AirSurveyTemp ($temp : TheTemp ) over window:time(5m) ;
$myList : collectList($cc),
$number : count($cc),
$min : min($temp),
$max : max($temp) ;
$max-$min < 11 )
then
System.out.println("-- Clear Alert "+ $a.getCondition() + "Number of
Object: " + " - Number of Object: " + $number + " - Min Value = "
+ $min + " - Max Value: " + $max );
retract($a);
clear.clear();
clear.addAll($myList);
end
rule "Trending Sampling window 5m"
salience 1
no-loop
when
accumulate( $cc : AirSurveyTemp ($temp : TheTemp ) over window:time(5m) ;
$myList : collectList($cc),
$number : count($cc),
$min : min($temp),
$max : max($temp)
)
then
sampling.clear();
sampling.addAll($myList);
end
{code}