I'm going to first write core unit tests around the rete dsl, as
it's easier to test multi permutations for left/right input
triggering and will better stop future regressions.
At the same time i'm applying the fixes, which needs to be done to
each node. In essence the code to get the memory iterator and the
first entry for each left tuple assertion needs to be applied to
each right object assertions and all the modifies.
I have isolated the
issue and know what it is, and why it works one way and not
the other. In short on unification if the variable is
unbound we need to turn off indexing for that specific join
attempt. We do this when it's left triggered, we don't do
this when it's right triggered. Updated the code to also do
this on right triggering. Should have it fixed tonight.
Thanks
Mark
On 25/06/2011 12:38, Mark Proctor wrote:
ok thanks, I reproduced the
problem with the following below. If you change the
String insertion order it works. I'll get this fixed
over the weekend:
@Test
public void testQueryWithObject() throws Exception
{
String str = "" +
"package org.drools.test \n" +
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
List<Integer> list = new
ArrayList<Integer>();
ksession.setGlobal( "list", list );
// This rule prints all
objects in WM.
rule findObject
when
$o: Object()
then
System.out.println( "Object: " + $o );
end
Happily I get
Object: 42
Object: a String object
Object:
org.drools.reteoo.InitialFactImpl@4dde85f0
Now the query way:
query object( Object o )
o := Object()
end
rule findObjectByQuery
when
object( $a ; )
then
System.out.println( "Object by query: " + $a
);
end
Surprisingly, I get just one:
Object by query:
org.drools.reteoo.InitialFactImpl@4dde85f0
A marvellous effect can be observed when the
condition in rule
findObjectByQuery is modified to
when
Object()
object( $a ; )
then
I'd have guessed that the above result would appear
repeatedly, once for each Object in WM,
but that's not so. For N-1 facts the rule fires
N*(N+1)/2 times, showing the "initial object"
N times, the first inserted object N-1 times, the
second one N-2 times and, finally, the last one
once.
Object by query: 42
Object by query:
org.drools.reteoo.InitialFactImpl@4dde85f0
Object by query: a String object
Object by query: 100
Object by query: 42
Object by query:
org.drools.reteoo.InitialFactImpl@4dde85f0
Object by query: a String object
Object by query:
org.drools.reteoo.InitialFactImpl@4dde85f0
Object by query: a String object
Object by query:
org.drools.reteoo.InitialFactImpl@4dde85f0