Hi,
Edson quoted the following sample rule some time ago:
rule "transaction consistency"
when
Transaction( $id : id )
$credits: Double( )
from accumulate( TransactionEntry( id == $id, operation ==
"credit", $amount : amount ),
init( double balance = 0 ),
action( balance += $amount ),
result( new Double( balance ) ) );
$debits: Double( )
from accumulate( TransactionEntry( id == $id, operation ==
"debit", $amount : amount ),
init( double balance = 0 ),
action( balance -= $amount ),
result( new Double( balance ) ) );
eval( ! $credits.equals( $debits ) ) then
// inconsistency for transaction $id
End
If there are 100 transactions overall and only 10 unique transaction ids
(eg, id = 1..10), so that we have on average 10 Transaction facts per id,
- how many times will 'eval' be called?
- how many times will the action be called, assuming 'eval' always returns
'true'?
I guess the answer for the above should be '10 times', once per each id?
What if I put another eval statement like "eval($id == 1)" after existing
'eval'? Would that be evaluated 100 times (for all Transaction facts) or
only 10 times (once per unique id)?
I think I'm missing quite significant piece on how tuples are selected in
DROOLS and how 'eval' and new 'from accumulate' features work.... Any
pointers would be greatly appreciated! (would some general literature on
rule engines help to clear up this types of questions?...)
Thanks,
Vlad
PS: sorry for posting so many questions and answering so few.....