Search in sources :

Example 6 with BaseAccumulation

use of org.drools.core.reteoo.AccumulateNode.BaseAccumulation in project drools by kiegroup.

the class PhreakAccumulateNode method doLeftUpdates.

private void doLeftUpdates(AccumulateNode accNode, AccumulateMemory am, ReteEvaluator reteEvaluator, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
    BetaMemory bm = am.getBetaMemory();
    TupleMemory rtm = bm.getRightTupleMemory();
    Accumulate accumulate = accNode.getAccumulate();
    ContextEntry[] contextEntry = bm.getContext();
    BetaConstraints constraints = accNode.getRawConstraints();
    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        BaseAccumulation accctx = (BaseAccumulation) leftTuple.getContextObject();
        if (accNode.isRightInputIsRiaNode()) {
            // This is a subnetwork, do not process further. As all matches will processed
            // by the right updates. This is to avoid double iteration (first right side iteration
            // then left side iteration) or for the join to find matching tuple chains, which it previously
            // did via subsumption checking.
            leftTuple.clearStaged();
            trgLeftTuples.addUpdate(leftTuple);
            leftTuple = next;
            continue;
        }
        constraints.updateFromTuple(contextEntry, reteEvaluator, leftTuple);
        FastIterator rightIt = accNode.getRightIterator(rtm);
        RightTuple rightTuple = accNode.getFirstRightTuple(leftTuple, rtm, rightIt);
        LeftTuple childLeftTuple = leftTuple.getFirstChild();
        // if rightTuple is null, we assume there was a bucket change and that bucket is empty
        if (childLeftTuple != null && rtm.isIndexed() && !rightIt.isFullIterator() && (rightTuple == null || (rightTuple.getMemory() != childLeftTuple.getRightParent().getMemory()))) {
            // our index has changed, so delete all the previous matchings
            removePreviousMatchesForLeftTuple(accumulate, leftTuple, reteEvaluator, am, accctx, true);
            // null so the next check will attempt matches for new bucket
            childLeftTuple = null;
        }
        // we can't do anything if RightTupleMemory is empty
        if (rightTuple != null) {
            doLeftUpdatesProcessChildren(accNode, am, reteEvaluator, bm, accumulate, constraints, rightIt, leftTuple, accctx, rightTuple, childLeftTuple);
        }
        leftTuple.clearStaged();
        trgLeftTuples.addUpdate(leftTuple);
        leftTuple = next;
    }
    constraints.resetTuple(contextEntry);
}
Also used : BetaConstraints(org.drools.core.common.BetaConstraints) BetaMemory(org.drools.core.reteoo.BetaMemory) BaseAccumulation(org.drools.core.reteoo.AccumulateNode.BaseAccumulation) FastIterator(org.drools.core.util.FastIterator) LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) AccumulateContextEntry(org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry) ContextEntry(org.drools.core.rule.ContextEntry) Accumulate(org.drools.core.rule.Accumulate)

Example 7 with BaseAccumulation

use of org.drools.core.reteoo.AccumulateNode.BaseAccumulation in project drools by kiegroup.

the class PhreakAccumulateNode method doLeftInserts.

private void doLeftInserts(AccumulateNode accNode, AccumulateMemory am, ReteEvaluator reteEvaluator, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
    Accumulate accumulate = accNode.getAccumulate();
    BetaMemory bm = am.getBetaMemory();
    TupleMemory ltm = bm.getLeftTupleMemory();
    TupleMemory rtm = bm.getRightTupleMemory();
    ContextEntry[] contextEntry = bm.getContext();
    BetaConstraints constraints = accNode.getRawConstraints();
    boolean leftTupleMemoryEnabled = accNode.isLeftTupleMemoryEnabled();
    for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        boolean useLeftMemory = leftTupleMemoryEnabled || RuleNetworkEvaluator.useLeftMemory(accNode, leftTuple);
        if (useLeftMemory) {
            ltm.add(leftTuple);
        }
        BaseAccumulation accresult = initAccumulationContext(am, reteEvaluator, accumulate, leftTuple);
        if (accNode.isRightInputIsRiaNode()) {
            // This is a subnetwork, do not process further. As all matches will processed
            // by the right insert. This is to avoid double iteration (first right side iteration
            // then left side iteration) or for the join to find matching tuple chains, which it previously
            // did via subsumption checking.
            leftTuple.clearStaged();
            trgLeftTuples.addInsert(leftTuple);
            leftTuple = next;
            continue;
        }
        constraints.updateFromTuple(contextEntry, reteEvaluator, leftTuple);
        FastIterator rightIt = accNode.getRightIterator(rtm);
        for (RightTuple rightTuple = accNode.getFirstRightTuple(leftTuple, rtm, rightIt); rightTuple != null; ) {
            RightTuple nextRightTuple = (RightTuple) rightIt.next(rightTuple);
            if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandleForEvaluation())) {
                // add a match
                addMatch(accNode, accumulate, leftTuple, rightTuple, null, null, reteEvaluator, am, accresult, useLeftMemory, true);
            }
            rightTuple = nextRightTuple;
        }
        leftTuple.clearStaged();
        trgLeftTuples.addInsert(leftTuple);
        constraints.resetTuple(contextEntry);
        leftTuple = next;
    }
    constraints.resetTuple(contextEntry);
}
Also used : BetaConstraints(org.drools.core.common.BetaConstraints) BetaMemory(org.drools.core.reteoo.BetaMemory) BaseAccumulation(org.drools.core.reteoo.AccumulateNode.BaseAccumulation) FastIterator(org.drools.core.util.FastIterator) LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) AccumulateContextEntry(org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry) ContextEntry(org.drools.core.rule.ContextEntry) Accumulate(org.drools.core.rule.Accumulate)

Aggregations

BaseAccumulation (org.drools.core.reteoo.AccumulateNode.BaseAccumulation)7 LeftTuple (org.drools.core.reteoo.LeftTuple)7 TupleMemory (org.drools.core.reteoo.TupleMemory)5 Accumulate (org.drools.core.rule.Accumulate)5 BetaMemory (org.drools.core.reteoo.BetaMemory)4 RightTuple (org.drools.core.reteoo.RightTuple)4 BetaConstraints (org.drools.core.common.BetaConstraints)3 AccumulateContextEntry (org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry)3 ContextEntry (org.drools.core.rule.ContextEntry)3 FastIterator (org.drools.core.util.FastIterator)3 AbstractHashTable (org.drools.core.util.AbstractHashTable)1