return 0;
}
public StagedLeftTuples eval( LeftTupleSource node, Memory nodeMem, SegmentMemory[] smems, int smemIndex, StagedLeftTuples trgTuples, StagedLeftTuples stagedLeftTuples, InternalWorkingMemory wm) {
StagedLeftTuples srcTuples = null;
boolean foundSegmentTip = false;
SegmentMemory smem = smems[smemIndex];
while ( true ) {
srcTuples = trgTuples; // previous target, is now the source
if ( NodeTypeEnums.isTerminalNode( node ) ) {
RuleTerminalNode rtn = rmem.getRuleTerminalNode();
pRtnNode.doNode( rtn, wm, srcTuples );
break; // returns null;
} else if ( NodeTypeEnums.RightInputAdaterNode == node.getType() ) {
return trgTuples;
} else if ( nodeMem == null ) {
// Reached end of segment, start on new segment.
SegmentPropagator.propagate( smem, trgTuples, wm );
smem = smems[smemIndex++];
node = smem.getRootNode();
nodeMem = smem.getNodeMemories().getFirst();
}
if ( node == smem.getTipNode() && smem.getFirst() != null) {
// we are about to process the segment tip, so allow it to merge insert/update/delete clashes
// can be null if next sink is RTN, or RiaNode
stagedLeftTuples = smem.getFirst().getStagedLeftTuples();
} else {
stagedLeftTuples = null;
}
trgTuples = new StagedLeftTuples();
if ( NodeTypeEnums.isBetaNode( node ) ) {
BetaNode betaNode = ( BetaNode )node;
BetaMemory bm = (BetaMemory) nodeMem;
if ( betaNode.isRightInputIsRiaNode() ) {
StagedLeftTuples peerTuples = new StagedLeftTuples();
SegmentPropagator.processPeers( srcTuples, peerTuples, betaNode );
// Make sure subnetwork Segment has tuples to process
SegmentMemory subSmem = bm.getSubnetworkSegmentMemory();
StagedLeftTuples subnetworkStaged = subSmem.getStagedLeftTuples();
subnetworkStaged.addAllDeletes( srcTuples.getDeleteFirst() );
subnetworkStaged.addAllUpdates( srcTuples.getUpdateFirst() );
subnetworkStaged.addAllInserts( srcTuples.getInsertFirst() );
List<RuleMemory> ruleMemories = subSmem.getRuleMemories();
RiaRuleMemory rm = null;
if ( ruleMemories.size() == 1 ) {
rm = ( RiaRuleMemory) ruleMemories.get( 0 ) ;
} else {
for ( int i = 0, size = ruleMemories.size(); i < size; i++ ) {
if ( ruleMemories.get( i ) instanceof RiaRuleMemory ) {
rm = ( RiaRuleMemory) ruleMemories.get( i ) ;
}
}
}
RightInputAdapterNode riaNode = ( RightInputAdapterNode ) betaNode.getRightInput();
// At this point we have the tuples to apply to the left and to the right of the subnetwork root node
StagedLeftTuples riaStagedTuples = eval( subSmem.getRootNode(), subSmem.getNodeMemories().getFirst(), rm.getSegmentMemories(), 0, srcTuples, null, wm );
StagedRightTuples riaStageRight = bm.getStagedRightTuples();
for ( LeftTuple leftTuple = riaStagedTuples.getInsertFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext() ) {
InternalFactHandle handle = riaNode.createFactHandle( leftTuple, leftTuple.getPropagationContext(), wm );
RightTuple rightTuple = betaNode.createRightTuple( handle, betaNode, leftTuple.getPropagationContext() );
//riaStagedTuples.
}
}
switch( node.getType() ) {
case NodeTypeEnums.JoinNode:
pJoinNode.doNode( (JoinNode) node, node.getSinkPropagator().getFirstLeftTupleSink(), bm, wm, srcTuples, trgTuples, stagedLeftTuples );
break;
case NodeTypeEnums.NotNode:
pNotNode.doNode( (NotNode) node, node.getSinkPropagator().getFirstLeftTupleSink(), bm, wm, srcTuples, trgTuples, stagedLeftTuples );
break;
case NodeTypeEnums.ExistsNode:
pExistsNode.doNode( (ExistsNode) node, node.getSinkPropagator().getFirstLeftTupleSink(), bm, wm, srcTuples, trgTuples, stagedLeftTuples );
break;
}
}
// LeftTupleSink sink = node.getSinkPropagator().getFirstLeftTupleSink();
//
//
// if ( node == smem.getTipNode() ) {
// smem.getSegmentPropagator().propagate( trgTuples, wm ); // merge children segments
// smem = smems[smemIndex++];
// node = smem.getRootNode();
// continue;
// }
if ( node.getSinkPropagator().size() > 1 ) {
// must be a subnetwork split, so create new staging area to handle left and right merging.
stagedLeftTuples = new StagedLeftTuples();
LeftTupleSource subNetworkNode = (LeftTupleSource) node.getSinkPropagator().getFirstLeftTupleSink();;
//eval( subNetworkNode, nodeMemory, )
}