use of org.drools.core.reteoo.AccumulateNode.GroupByContext 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);
}
}
use of org.drools.core.reteoo.AccumulateNode.GroupByContext in project drools by kiegroup.
the class PhreakGroupByNode method initAccumulationContext.
@Override
AccumulateNode.BaseAccumulation initAccumulationContext(AccumulateMemory am, ReteEvaluator reteEvaluator, Accumulate accumulate, LeftTuple leftTuple) {
GroupByContext accContext = new GroupByContext();
leftTuple.setContextObject(accContext);
// A lot less is done here, compared to super, as it needs to be done on demand during the Group creation.
return accContext;
}
use of org.drools.core.reteoo.AccumulateNode.GroupByContext 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);
}
use of org.drools.core.reteoo.AccumulateNode.GroupByContext 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);
}
}
use of org.drools.core.reteoo.AccumulateNode.GroupByContext 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;
}
Aggregations