Drools Fusion time based sliding window AND attribute filtre

1.4k Views Asked by At

I try to use a sliding time window in Drools 5.4.0.Final and given the following official documentation snippets:

StockTick() over window:time( 2m )

and

StockTick( company == "RHT" ) over window:length( 10 )

I was thinking that the mixed form was valid:

StockTick( company == "RHT" ) over window:time( 2m )

But, unless I'm mistaken, it doesn't behaves as expected (i.e consider only the RHT Stock Ticks that happened in the last 2 minutes). And I didn't understand the logic of the result.

Somebody could explain me the trick please ?

Thanks.

2

There are 2 best solutions below

0
On BEST ANSWER

Two Drools versions cause two different behaviors (same Unit Test). So I think my misunderstood comes from a bug in "windows" behavior. I can't be more specific this time.

1
On

Looking at drools-fusion-docs chapter 2.6.1. Sliding Time Windows there is an aggregating example. Here is a variation that should fit your need.

rule "At least one RHT in the last 2 minutes"
when
    Number( intValue > 0 ) from accumulate(
        $tick = StockTick( company == "RHT" ) over window:time( 2m ),
        count( $tick ) )
then
    // do something here
end