"not" and "accumulate" ordering LHS yield different counting - potential bug shall I raise JIRA?

115 views
Skip to first unread message

Matteo Mortari

unread,
Sep 3, 2014, 10:45:56 AM9/3/14
to drools...@googlegroups.com
Ciao, 
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.

Before I go ahead and raise a JIRA, I would like to double-check in case I'm missing something, please?

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 accumulatethe 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.
Conclusions
[>] Am I missing something, or indeed this sounds like a potential bug and therefore shall I go ahead and raise a JIRA, please?

Thanks

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

Mario Fusco

unread,
Sep 3, 2014, 11:16:09 AM9/3/14
to drools...@googlegroups.com
Hi Matteo,

for how you're describing it, it seems to be a bug (very likely caused by some spurious/unwanted node sharing). Could you please open a jira and send me that reproducer?

Thanks,
Mario


--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/435d7fba-de76-4815-a5ed-5014db11af59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matteo Mortari

unread,
Sep 3, 2014, 11:28:34 AM9/3/14
to drools...@googlegroups.com
Hi Mario, as always thank you for your prompt feedback.

Kindly allow me a couple of days to deliver the reproducer, the code is ready, but currently "collecting all the clearance at the Customs".

Thanks, Ciao
MM

Matteo Mortari

unread,
Sep 4, 2014, 5:45:03 AM9/4/14
to drools...@googlegroups.com
Ciao again, I think this was due to some spurious cache or spurious .class which should have refreshed but in fact, they did not. Issuing a Eclipse > Clean and mvn clean, surprisingly, solved the issue. Can you kindly close the JIRA, please.

I discovered this as I was "collecting all the clearance at the Customs" by replacing product branding with another fantasy name, this made me discover one drl file was missing in the stripped-down code version I was about to share, and once solved the test did, indeed, passed with the fantasy-name stripped-down code version. So I went back to the original-name stripped-down code version which I had ready on hand when I raised the jira yerstarday, I issued Cleans everywhere, put the missing drl file as well, test did indeed passed also with the original-name stripped-down code version.

> The only explanation I can give myself, besides some embarrassment, is that some spurious cache or spurious .class was out-of-sync.

I'm really, really, sorry for the noise; but honestly, I could not expect this to be solved by simply issuing a clean.

I will enforce cleans in the publishing processes, even in the case of small mods.
Thought worthy to share the details of how I found where the problem likely was.
Ciao
MM

Mario Fusco

unread,
Sep 4, 2014, 5:56:21 AM9/4/14
to drools...@googlegroups.com
Hi Matteo,

this is a good news :) I closed the jira.
Don't worry and keep sharing your suggestions, feedback and especially (possible) bugs. They're always valuable.

Thanks,
Mario



--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages