Search in sources :

Example 1 with TripleNonIndexSkipBetaConstraints

use of org.drools.core.common.TripleNonIndexSkipBetaConstraints in project drools by kiegroup.

the class IndexingTest method testIndexingOnQueryUnification.

@Test(timeout = 10000)
public void testIndexingOnQueryUnification() throws Exception {
    String str = "";
    str += "package org.drools.compiler.test  \n";
    str += "import org.drools.compiler.Person \n";
    str += "query peeps( String $name, String $likes, String $street) \n";
    str += "    $p : Person( $name := name, $likes := likes, $street := address.street ) \n";
    str += "end\n";
    KieBase kbase = loadKnowledgeBaseFromString(str);
    List<ObjectTypeNode> nodes = ((KnowledgeBaseImpl) kbase).getRete().getObjectTypeNodes();
    ObjectTypeNode node = null;
    for (ObjectTypeNode n : nodes) {
        if (((ClassObjectType) n.getObjectType()).getClassType() == DroolsQuery.class) {
            node = n;
            break;
        }
    }
    InternalWorkingMemory wm = ((StatefulKnowledgeSessionImpl) kbase.newKieSession());
    AlphaNode alphanode = (AlphaNode) node.getObjectSinkPropagator().getSinks()[0];
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) alphanode.getObjectSinkPropagator().getSinks()[0];
    // $p2
    JoinNode j = (JoinNode) liaNode.getSinkPropagator().getSinks()[0];
    TripleNonIndexSkipBetaConstraints c = (TripleNonIndexSkipBetaConstraints) j.getRawConstraints();
    // assertEquals( "$name", ((VariableConstraint)c.getConstraint()).getRequiredDeclarations()[0].getIdentifier() );
    assertTrue(c.isIndexed());
    BetaMemory bm = (BetaMemory) wm.getNodeMemory(j);
    assertTrue(bm.getLeftTupleMemory() instanceof TupleIndexHashTable);
    assertTrue(bm.getRightTupleMemory() instanceof TupleIndexHashTable);
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) TripleNonIndexSkipBetaConstraints(org.drools.core.common.TripleNonIndexSkipBetaConstraints) KieBase(org.kie.api.KieBase) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) BetaMemory(org.drools.core.reteoo.BetaMemory) TupleIndexHashTable(org.drools.core.util.index.TupleIndexHashTable) AlphaNode(org.drools.core.reteoo.AlphaNode) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) Test(org.junit.Test)

Aggregations

InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 TripleNonIndexSkipBetaConstraints (org.drools.core.common.TripleNonIndexSkipBetaConstraints)1 AlphaNode (org.drools.core.reteoo.AlphaNode)1 BetaMemory (org.drools.core.reteoo.BetaMemory)1 JoinNode (org.drools.core.reteoo.JoinNode)1 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1