LeftTupleSink sink,
LeftTuple leftTuple,
InternalWorkingMemory wm) {
if ( factHandleEntry != null ) {
LeftTuple leftParent = leftTuple.getLeftParent();
while ( leftTuple != null ) {
leftTuple = leftTuple.getLeftParentNext();
for ( ; leftTuple != null; leftTuple = leftTuple.getLeftParentNext() ) {
// Iterate to find the next left tuple for this sink, skip tuples for other sinks due to sharing split
if ( leftTuple.getLeftTupleSink() == sink ) {
return leftTuple;
}
}
}
// We have a parent LeftTuple so try there next
if ( leftParent != null ) {
// we know it has to be evalNode query element node
while ( leftParent != null ) {
if ( source instanceof EvalConditionNode ) {
leftParent = getNextLeftTuple( ((EvalConditionNode) source).getLeftTupleSource(),
(LeftTupleSink) source,
leftParent,
wm );
} else {
leftParent = getNextLeftTuple( ((QueryElementNode) source).getLeftTupleSource(),
(LeftTupleSink) source,
leftParent,
wm );
}
if ( leftParent != null ) {
for ( leftTuple = leftParent.getFirstChild(); leftTuple != null; leftTuple = leftTuple.getLeftParentNext() ) {
if ( leftTuple.getLeftTupleSink() == sink ) {
return leftTuple;
}
}
}
}
return null;
}
if ( factHandleEntry == null ) {
// we've exhausted this OTN
return null;
}
// We have exhausted the current FactHandle, now try the next
for ( factHandleEntry = (ObjectEntry) otnIterator.next(); factHandleEntry != null; factHandleEntry = (ObjectEntry) otnIterator.next() ) {
InternalFactHandle handle = (InternalFactHandle) factHandleEntry.getValue();
for ( leftTuple = handle.getFirstLeftTuple(); leftTuple != null; leftTuple = leftTuple.getLeftParentNext() ) {
if ( leftTuple.getLeftTupleSink() == sink ) {
return leftTuple;
}
}
}
// We've exhausted this OTN so set the iterator to null
factHandleEntry = null;
otnIterator = null;
} else if ( source instanceof JoinNode || source instanceof NotNode|| source instanceof FromNode || source instanceof AccumulateNode ) {
BetaMemory memory;
FastIterator localIt;
if ( source instanceof FromNode ) {
memory = ((FromMemory) wm.getNodeMemory( (NodeMemory) source )).betaMemory;
} else if ( source instanceof AccumulateNode ) {
memory = ((AccumulateMemory) wm.getNodeMemory( (NodeMemory) source )).betaMemory;
} else {
memory = (BetaMemory) wm.getNodeMemory( (NodeMemory) source );
}
localIt = memory.getLeftTupleMemory().fullFastIterator( leftTuple.getLeftParent() );
LeftTuple childLeftTuple = leftTuple;
if ( childLeftTuple != null ) {
leftTuple = childLeftTuple.getLeftParent();
while ( leftTuple != null ) {
if ( childLeftTuple == null ) {
childLeftTuple = leftTuple.getFirstChild();
} else {
childLeftTuple = childLeftTuple.getLeftParentNext();
}
for ( ; childLeftTuple != null; childLeftTuple = childLeftTuple.getLeftParentNext() ) {
if ( childLeftTuple.getLeftTupleSink() == sink ) {
return childLeftTuple;
}
}
leftTuple = (LeftTuple) localIt.next( leftTuple );
}
}
}
if ( source instanceof ExistsNode ) {
BetaMemory memory = (BetaMemory) wm.getNodeMemory( (NodeMemory) source );
RightTuple rightTuple = leftTuple.getLeftParent().getBlocker();
FastIterator localIt = memory.getRightTupleMemory().fullFastIterator( rightTuple );
for ( LeftTuple childleftTuple = leftTuple.getLeftParentNext(); childleftTuple != null; childleftTuple = childleftTuple.getLeftParentNext() ) {
if ( childleftTuple.getLeftTupleSink() == sink ) {
return childleftTuple;
}
}
leftTuple = leftTuple.getLeftParent();
// now move onto next RightTuple
while ( rightTuple != null ) {
if ( rightTuple.getBlocked() != null ) {
if ( leftTuple != null ) {
leftTuple = leftTuple.getBlockedNext();
} else {
leftTuple = rightTuple.getBlocked();
}
for ( ; leftTuple != null; leftTuple = leftTuple.getBlockedNext() ) {
for ( LeftTuple childleftTuple = leftTuple.getFirstChild(); childleftTuple != null; childleftTuple = childleftTuple.getLeftParentNext() ) {
if ( childleftTuple.getLeftTupleSink() == sink ) {
return childleftTuple;
}
}
}
}
rightTuple = (RightTuple) localIt.next( rightTuple );
}
} else if ( source instanceof EvalConditionNode || source instanceof QueryElementNode ) {
LeftTuple childLeftTuple = leftTuple;
if ( leftTuple != null ) {
leftTuple = leftTuple.getLeftParent();
while ( leftTuple != null ) {
if ( childLeftTuple != null ) {
childLeftTuple = childLeftTuple.getLeftParentNext();
} else {
childLeftTuple = leftTuple.getFirstChild();
}
for ( ; childLeftTuple != null; childLeftTuple = childLeftTuple.getLeftParentNext() ) {
if ( childLeftTuple.getLeftTupleSink() == sink ) {
return childLeftTuple;
}
}
if ( source instanceof EvalConditionNode ) {