[rules-users] accumulate vs collect

rouvas at di.uoa.gr rouvas at di.uoa.gr
Fri Nov 12 13:50:35 EST 2010


Edson Tirelli wrote:
>     I believe this is fixed in Drools 5.1.1, as in 5.0.1 declared
> beans where not implementing the Serializable interface. Please try
> 5.1.1 and let us know if you still see the problem.

Unfortunately I am the final stages of my project and cannot afford to
switch Drools versions.
I expect to be able to to such changes in a couple of months in the next
upgrade cycle. I'll try to remember this case and will report any new
findings.

>
>    Otherwise, Wolfgang's suggestion for the workaround should work as
> well.

I did that and it works fine. I consider the issue closed (for the time
being).

Thank you all for your time,
-Stathis

>
>     Edson
>
> 2010/11/12  <rouvas at di.uoa.gr>:
>> Edson Tirelli wrote:
>>>    Can you show us the stack trace? What version of Drools are you
>>> using?
>>
>> I am using Drools.5.0.1.
>>
>> For this accumulate:
>>
>> v945 : Number ( doubleValue  >=  1 ) from accumulate ( p : t_1 (  c_6 >=
>> 20100512 && c_7 == "5" ) , count(p) )
>>
>> stack trace follows:
>>
>> EXCEPTION ERROR
>> java.lang.ClassCastException: gr.fbi.rulez.t_1
>> org.drools.rule.Accumulate.accumulate(Accumulate.java:172)
>> org.drools.reteoo.AccumulateNode.modifyTuple(AccumulateNode.java:424)
>> org.drools.reteoo.AccumulateNode.assertObject(AccumulateNode.java:284)
>> org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:42)
>> org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:147)
>> org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:42)
>> org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:147)
>> org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:42)
>> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:185)
>> org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:146)
>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1046)
>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1001)
>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:788)
>> org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:216)
>> utils.LoadDynEntities.load(LoadDynEntities.java:102)
>> gr.fbi.rulez.RulesRunner.ignite(RulesRunner.java:74)
>> ...more irrelevant stuff..
>>
>> -Stathis
>>
>>
>>>
>>>    In Drools 5.1+, collect is just syntax sugar... internally, collect
>>> is implemented using accumulate.
>>>
>>>    Edson
>>>
>>> 2010/11/11  <rouvas at di.uoa.gr>:
>>>> Hi List,
>>>>
>>>> I'm trying to count the number of objects I have in the Working Memory
>>>> using accumulate, but I'm having a ClassCastException thrown at me.
>>>>
>>>> Using a variant with collect, everything work OK.
>>>>
>>>> Can someone shed some light on this issue?
>>>> Is it related to https://jira.jboss.org/browse/JBRULES-2202 ?
>>>>
>>>> I'm using Drools.5.0.1 and the fact is a declared one, as follows:
>>>>
>>>> declare t_1
>>>>  regRowId : String
>>>>  versionId : String
>>>>  c_7 : String
>>>>  c_1 : String
>>>>  c_2 : String
>>>>  c_3 : String
>>>>  c_4 : String
>>>>  c_5 : String
>>>>  c_6 : Double
>>>> end
>>>>
>>>> trying with :
>>>>
>>>> v945 : Number ( doubleValue  >=  1 ) from accumulate ( p : t_1 (  c_6
>>>> >=
>>>> 20100511 && c_7 == "5" ) , count(p) )
>>>>
>>>> I'm getting a ClassCastException:t_1, while using :
>>>>
>>>> v945 : ArrayList ( size  >=  1 ) from collect ( t_1 (  c_6 >= 20100511
>>>> &&
>>>> c_7 == "5" )  )
>>>>
>>>> works OK.
>>>>
>>>> The reason I'm preferring accumulate over collect, is that I'm not
>>>> really
>>>> interested in constructing an ArrayList of the matched facts (worries
>>>> about memory consumption), all I want is how many of them are there.
>>>>
>>>> The actual rule I'm using (although I don't think it matters) for the
>>>> accumulate variant, is:
>>>>
>>>> rule "r95944.6"
>>>>        dialect "mvel"
>>>>        when
>>>>                gnId : GoodNumbers()
>>>>                 LogicalValue : Trader( gnId.goodNo==goodNo  )
>>>>                 v945 : Number ( doubleValue  >=  1 ) from accumulate (
>>>> p
>>>> : t_1 (  c_6
>>>>>= 20100511 && c_7 == "5" ) , count(p) )
>>>>        then
>>>>                RaResultCode rrc = new RaResultCode();
>>>>                  rrc.setResultRuleId("95944");
>>>>                  rrc.setResultRuleVersionId("6");
>>>>                  rrc.setResultColor("R");
>>>>                  rrc.setResultRuleCode("01");
>>>>                  rrc.setResultAction("1");
>>>>                  rrc.setResultGoodNo(gnId.goodNo);
>>>>                insertLogical(rrc);
>>>> end
>>>>
>>>> Thank you for your time.
>>>>
>>>> -Stathis
>>>>
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>
>>>
>>>
>>> --
>>>   Edson Tirelli
>>>   JBoss Drools Core Development
>>>   JBoss by Red Hat @ www.jboss.com
>>>
>>
>>
>
>
>
> --
>   Edson Tirelli
>   JBoss Drools Core Development
>   JBoss by Red Hat @ www.jboss.com
>





More information about the rules-users mailing list