Search in sources :

Example 1 with AccumulateContextEntry

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

the class PhreakGroupByNode method reaccumulateForLeftTuple.

@Override
protected void reaccumulateForLeftTuple(final AccumulateNode accNode, final Accumulate accumulate, final LeftTuple leftTuple, final RightTuple rightParent, final LeftTuple match, final ReteEvaluator reteEvaluator, final AccumulateMemory am, final AccumulateNode.BaseAccumulation accctx, final boolean reaccumulate) {
    GroupByContext groupByContext = (GroupByContext) accctx;
    if (match != null) {
        // re-accumulate just for the sub group
        TupleList<AccumulateContextEntry> tupleList = match.getMemory();
        tupleList.remove(match);
        if (reaccumulate) {
            // re-init function context for the group
            Object functionContext = accumulate.createFunctionContext();
            tupleList.getContext().setFunctionContext(functionContext);
            for (LeftTuple childMatch = (LeftTuple) tupleList.getFirst(); childMatch != null; childMatch = (LeftTuple) childMatch.getNext()) {
                RightTuple rightTuple = childMatch.getRightParent();
                InternalFactHandle childHandle = rightTuple.getFactHandle();
                LeftTuple tuple = leftTuple;
                if (accNode.isRightInputIsRiaNode()) {
                    // if there is a subnetwork, handle must be unwrapped
                    tuple = (LeftTuple) rightTuple;
                    childHandle = rightTuple.getFactHandleForEvaluation();
                }
                Object value = accumulate.accumulate(am.workingMemoryContext, tuple, childHandle, groupByContext, tupleList, reteEvaluator);
                match.setContextObject(value);
            }
        }
    } else {
        // re-accumulate all groups
        groupByContext.clear();
        super.reaccumulateForLeftTuple(accNode, accumulate, leftTuple, null, null, reteEvaluator, am, accctx, true);
    }
}
Also used : GroupByContext(org.drools.core.reteoo.AccumulateNode.GroupByContext) InternalFactHandle(org.drools.core.common.InternalFactHandle) LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) AccumulateContextEntry(org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry)

Example 2 with AccumulateContextEntry

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

the class LambdaGroupByAccumulate method accumulate.

@Override
public Object accumulate(Object workingMemoryContext, Object context, Tuple match, InternalFactHandle handle, ReteEvaluator reteEvaluator) {
    GroupByContext groupByContext = (GroupByContext) context;
    TupleList<AccumulateContextEntry> tupleList = groupByContext.getGroup(workingMemoryContext, innerAccumulate, match, getKey(match, handle, reteEvaluator), reteEvaluator);
    return accumulate(workingMemoryContext, match, handle, groupByContext, tupleList, reteEvaluator);
}
Also used : GroupByContext(org.drools.core.reteoo.AccumulateNode.GroupByContext) AccumulateContextEntry(org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry)

Example 3 with AccumulateContextEntry

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

the class PhreakAccumulateNode method propagateDelete.

protected void propagateDelete(TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples, Object accPropCtx) {
    AccumulateContextEntry entry = (AccumulateContextEntry) accPropCtx;
    if (entry.isPropagated()) {
        normalizeStagedTuples(stagedLeftTuples, entry.getResultLeftTuple());
        trgLeftTuples.addDelete(entry.getResultLeftTuple());
    }
}
Also used : AccumulateContextEntry(org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry)

Example 4 with AccumulateContextEntry

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

the class PhreakGroupByNode method evaluateResultConstraints.

@Override
protected void evaluateResultConstraints(final AccumulateNode accNode, final LeftTupleSink sink, final Accumulate accumulate, final LeftTuple leftTuple, final PropagationContext context, final ReteEvaluator reteEvaluator, final AccumulateMemory memory, final AccumulateNode.BaseAccumulation accctx, final TupleSets<LeftTuple> trgLeftTuples, final TupleSets<LeftTuple> stagedLeftTuples) {
    PropagationContext propagationContext = accctx.getPropagationContext();
    accctx.setPropagationContext(null);
    GroupByContext groupByContext = (GroupByContext) accctx;
    for (TupleList<AccumulateContextEntry> tupleList = groupByContext.takeToPropagateList(); tupleList != null; tupleList = tupleList.getNext()) {
        AccumulateContextEntry contextEntry = tupleList.getContext();
        Object result = accumulate.getResult(memory.workingMemoryContext, contextEntry, leftTuple, reteEvaluator);
        propagateResult(accNode, sink, leftTuple, context, reteEvaluator, memory, trgLeftTuples, stagedLeftTuples, contextEntry.getKey(), result, contextEntry, propagationContext, // don't want to propagate null
        false);
        contextEntry.setToPropagate(false);
    }
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) GroupByContext(org.drools.core.reteoo.AccumulateNode.GroupByContext) AccumulateContextEntry(org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry)

Example 5 with AccumulateContextEntry

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

the class LambdaGroupByAccumulate method tryReverse.

@Override
public boolean tryReverse(Object workingMemoryContext, Object context, Tuple leftTuple, InternalFactHandle handle, RightTuple rightParent, LeftTuple match, ReteEvaluator reteEvaluator) {
    TupleList<AccumulateContextEntry> memory = match.getMemory();
    AccumulateContextEntry entry = memory.getContext();
    boolean reversed = innerAccumulate.tryReverse(workingMemoryContext, entry, leftTuple, handle, rightParent, match, reteEvaluator);
    if (reversed) {
        GroupByContext groupByContext = (GroupByContext) context;
        groupByContext.moveToPropagateTupleList(match.getMemory());
        memory.remove(match);
        if (memory.isEmpty()) {
            groupByContext.removeGroup(entry.getKey());
            memory.getContext().setEmpty(true);
        }
    }
    return reversed;
}
Also used : GroupByContext(org.drools.core.reteoo.AccumulateNode.GroupByContext) AccumulateContextEntry(org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry)

Aggregations

AccumulateContextEntry (org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry)5 GroupByContext (org.drools.core.reteoo.AccumulateNode.GroupByContext)4 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 LeftTuple (org.drools.core.reteoo.LeftTuple)1 RightTuple (org.drools.core.reteoo.RightTuple)1 PropagationContext (org.drools.core.spi.PropagationContext)1