On 27/06/2011 10:38, Wolfgang Laun wrote:
I saw a commit and tried again, but the problem is still around.
I added a test to BackwardChainingTest - see the pull request.
I have created a jira to track this:
https://issues.jboss.org/browse/JBRULES-3101

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.

commit here shows me updating the rete dsl testing engine for queries:
https://github.com/droolsjbpm/drools/commit/279c9df98434d668d6adc837982a40ae6b9c97d3

i've added a basic test to start with that shows it working for right then left triggering, but failing for left then right triggering.
https://github.com/droolsjbpm/drools/blob/279c9df98434d668d6adc837982a40ae6b9c97d3/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeUnificationTest.nodeTestCase

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.

Mark

-W

On 25 June 2011 14:10, Mark Proctor <mproc...@codehaus.org <mailto:mproc...@codehaus.org>> wrote:

    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" +

                "import java.util.List\n" +
                "import java.util.ArrayList\n" +

                "global List list\n" +

                "dialect \"mvel\"\n" +
                "\n" +

                "import
    org.drools.integrationtests.BackwardChainingTest.Q\n" +
                "import
    org.drools.integrationtests.BackwardChainingTest.R\n" +
                "import
    org.drools.integrationtests.BackwardChainingTest.S\n" +

                "query object(Object o)\n" +
                "    o := Object() \n" +
                "end\n" +

                "rule collectObjects when\n" +
                "   String( this == 'go1' )\n" +
                "   object( o; )\n" +
                "then\n" +
                "   list.add( o );\n" +
                "end\n" +


                "rule init when\n" +
                "   String( this == 'init' )\n" +
                "then\n" +
                " insert( new Q(1) );\n " +
                " insert( new Q(5) );\n " +
                " insert( new Q(6) );\n " +
                " insert( new R(1) );\n " +
                " insert( new R(4) );\n " +
                " insert( new R(6) );\n " +
                " insert( new R(2) );\n " +
                " insert( new S(2) );\n " +
                " insert( new S(3) );\n " +
                " insert( new S(6) );\n " +
                "end\n" +
                "";

            KnowledgeBuilder kbuilder =
    KnowledgeBuilderFactory.newKnowledgeBuilder();
            kbuilder.add( ResourceFactory.newByteArrayResource(
    str.getBytes() ),
                              ResourceType.DRL );

            if ( kbuilder.hasErrors() ) {
                fail( kbuilder.getErrors().toString() );
            }

            KnowledgeBase kbase =
    KnowledgeBaseFactory.newKnowledgeBase();
            kbase.addKnowledgePackages(
    kbuilder.getKnowledgePackages() );

            kbase = SerializationHelper.serializeObject( kbase );

            StatefulKnowledgeSession ksession =
    kbase.newStatefulKnowledgeSession();
            List<Integer> list = new ArrayList<Integer>();
            ksession.setGlobal( "list", list );

            ksession.insert( "go1" );
            ksession.fireAllRules();

            ksession.insert( "init" );
            ksession.fireAllRules();

            System.out.println( list );
        }

    Mark
    On 25/06/2011 11:22, Wolfgang Laun wrote:
    // 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

    -W


    _______________________________________________
    rules-dev mailing list
    rules-dev@lists.jboss.org  <mailto:rules-dev@lists.jboss.org>
    https://lists.jboss.org/mailman/listinfo/rules-dev


    _______________________________________________
    rules-dev mailing list
    rules-dev@lists.jboss.org  <mailto:rules-dev@lists.jboss.org>
    https://lists.jboss.org/mailman/listinfo/rules-dev


    _______________________________________________
    rules-dev mailing list
    rules-dev@lists.jboss.org <mailto:rules-dev@lists.jboss.org>
    https://lists.jboss.org/mailman/listinfo/rules-dev



_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev

_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev

Reply via email to