org.eigenbase.runtime
Class NestedLoopCalcTupleIter

java.lang.Object
  extended by org.eigenbase.runtime.CalcTupleIter
      extended by org.eigenbase.runtime.NestedLoopCalcTupleIter
All Implemented Interfaces:
TupleIter, ClosableAllocation

public abstract class NestedLoopCalcTupleIter
extends CalcTupleIter

NestedLoopCalcTupleIter is a specialization of CalcTupleIter for use in implementing nested loop inner joins over iterators.

REVIEW jvs 20-Mar-2004: I have parameterized this to handle inner and left outer joins, as well as one-to-many and many-to-one variants. This comes at the price of some efficiency. It would probably be better to write specialized bases for each purpose.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/runtime/NestedLoopCalcTupleIter.java#9 $
Author:
John V. Sichi

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.eigenbase.runtime.TupleIter
TupleIter.NoDataReason, TupleIter.TimeoutException
 
Field Summary
private  boolean isLeftOuter
           
private  boolean isOpen
           
protected  Object leftObj
           
private  boolean needNullRow
           
protected  Object rightIterator
           
protected  Object rightObj
           
 
Fields inherited from class org.eigenbase.runtime.CalcTupleIter
inputIterator
 
Fields inherited from interface org.eigenbase.runtime.TupleIter
EMPTY_ITERATOR
 
Constructor Summary
protected NestedLoopCalcTupleIter(TupleIter leftIterator, boolean isLeftOuter)
           
 
Method Summary
protected abstract  Object calcJoinRow()
          Method to be implemented by subclasses to either calculate the next joined row based on current values of leftObj and rightObj, or else to filter out this combination.
protected  Object calcRightNullRow()
          Method to be implemented by subclasses to calculate a mismatch row in a left outer join.
 Object fetchNext()
          Returns the next element in the iteration.
protected abstract  Object getNextRightIterator()
          Method to be implemented by subclasses to determine next right-hand iterator based on current value of leftObj.
protected  void open()
          Method which can be overridden by subclasses to carry out post-constructor initialization.
 
Methods inherited from class org.eigenbase.runtime.CalcTupleIter
closeAllocation, restart, setTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rightIterator

protected Object rightIterator

leftObj

protected Object leftObj

rightObj

protected Object rightObj

isOpen

private boolean isOpen

isLeftOuter

private boolean isLeftOuter

needNullRow

private boolean needNullRow
Constructor Detail

NestedLoopCalcTupleIter

protected NestedLoopCalcTupleIter(TupleIter leftIterator,
                                  boolean isLeftOuter)
Method Detail

fetchNext

public Object fetchNext()
Description copied from interface: TupleIter
Returns the next element in the iteration. If there is no next value, it returns a value from the TupleIter.NoDataReason enumeration indicating why no data was returned.

If this method returns TupleIter.NoDataReason.END_OF_DATA, no further data will be returned by this iterator unless TupleIter.restart() is called.

If this method returns TupleIter.NoDataReason.UNDERFLOW, no data is currently available, but may be come available in the future. It is possible for consecutive calls to return UNDERFLOW and then END_OF_DATA.

The object returned by this method may be re-used for each subsequent call to fetchNext(). In other words, callers must either make certain that the returned value is no longer needed or is copied before any subsequent calls to fetchNext().

Returns:
the next element in the iteration, or an instance of TupleIter.NoDataReason.

open

protected void open()
Method which can be overridden by subclasses to carry out post-constructor initialization.


getNextRightIterator

protected abstract Object getNextRightIterator()
Method to be implemented by subclasses to determine next right-hand iterator based on current value of leftObj. For a many-to-one join, this can return the right-hand object directly instead of a TupleIter, but should return TupleIter.EMPTY_ITERATOR for a mismatch.

Returns:
iterator or object

calcJoinRow

protected abstract Object calcJoinRow()
Method to be implemented by subclasses to either calculate the next joined row based on current values of leftObj and rightObj, or else to filter out this combination.

Returns:
row or null for filtered oute

calcRightNullRow

protected Object calcRightNullRow()
Method to be implemented by subclasses to calculate a mismatch row in a left outer join. Inner joins can use the default (return null) because it will never be called.

Returns:
row with all right fields set to null