[rules-users] how to count distinct nested property?
Hi, I’m trying to wrap my head around how to use a combination of accumulate from and collect from to get a count of how many unique items there are of a nested child property and run the RHS of a rule if it’s 1 So I have Many of Object A Each one contains An object B An object C Object C contains a nested child property So A +-+-B | +-C – property myId (many of these in the working memory) The rule I’m working with right now is rule B must only be at 1 myId per day when $b : B() $c : C() $aList : ArrayList (size 1) from collect( A(b == $b, c.getDate() == $c.getDate()) ) eval ( RulesUtils.countIdsForC ($aList) 1 ) then //fire some rules here end and the RulesUtils method is public static int countIdsForC (List aList) { SetInteger myIds = new HashSetInteger(); for (A a : aList) { myIds.add(a.getC().getMyId()); } return myIds.size(); } Now I’m well aware that this is sub-optimal, and indeed is firing lots of extra times and is really (Really) slow. I can vizualise that this should easily be possible with some combination of compound accumulate and collect statements, but for the life of me I can’t work out the correct arrangement (This is actually for use in an optaplanner ruleset so it will potentially be working on lots of data, over many iterations). Any suggestions on how to do this the way I know it needs to be, greatfully appreciated -- View this message in context: http://drools.46999.n3.nabble.com/how-to-count-distinct-nested-property-tp4030424.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools 6 Junit Random Failures
Okay, after much investigation, it turns out the tests were A) using .execute, rather than insert and fireallrules type behaviour, so i refactored that to improve them a bit (gave me more control). after that, and using the debug tools suggested it lead me to the root cause of the problem. someone when constructing the inbound facts had called Calendar.getInstance() mutiple times, for different fields, which should actually have been the same date/time, and hence sometimes the tests passed, sometimes they failed. sorted it now :-) -- View this message in context: http://drools.46999.n3.nabble.com/Drools-6-Junit-Random-Failures-tp4029379p4029387.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users