com.bigdata.btree.view
Class FusedTupleIterator<I extends ITupleIterator<E>,E>

java.lang.Object
  extended by com.bigdata.btree.view.FusedTupleIterator<I,E>
All Implemented Interfaces:
ITupleIterator<E>, Iterator<ITuple<E>>
Direct Known Subclasses:
FusedTupleCursor

public class FusedTupleIterator<I extends ITupleIterator<E>,E>
extends Object
implements ITupleIterator<E>

An aggregate iterator view of the one or more source ITupleIterators.

Version:
$Id: FusedTupleIterator.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
FusedView.rangeIterator(byte[], byte[], int, int, com.bigdata.btree.filter.IFilterConstructor)

Field Summary
protected  int current
          Index into sourceIterator and sourceTuple of the iterator whose tuple will be returned next -or- -1 if we need to choose the next ITuple to be visited.
protected  boolean DEBUG
          True iff the log level is DEBUG or less.
protected  boolean deleted
          True iff IRangeQuery.DELETED semantics will be applied (that is, true if the caller wants to see the deleted tuples).
protected  int flags
          The flags specified to the ctor.
protected  boolean INFO
          True iff the log level is INFO or less.
protected  int lastVisited
          The index into sourceIterator of the iterator whose tuple was last returned by next().
protected static org.apache.log4j.Logger log
           
protected  int n
          The #of source iterators.
protected  I[] sourceIterator
          The source iterators in the order given to the ctor.
protected  ITuple<E>[] sourceTuple
          The current ITuple from each source and null if we need to get another ITuple from that source.
 
Constructor Summary
FusedTupleIterator(int flags, boolean deleted, I[] sourceIterators)
          Create an ITupleIterator reading from an ordered set of source ITupleIterators.
 
Method Summary
protected  void clearCurrent()
           Clear tuples from other sources having the same key as the current tuple.
protected  ITuple<E> consumeLookaheadTuple()
          Consume the current source ITuple.
 boolean hasNext()
           
 ITuple<E> next()
          Advance the iterator and return the ITuple from which you can extract the data and metadata for next entry.
 void remove()
          Operation is not supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

INFO

protected final boolean INFO
True iff the log level is INFO or less.


DEBUG

protected final boolean DEBUG
True iff the log level is DEBUG or less.


flags

protected final int flags
The flags specified to the ctor.


deleted

protected final boolean deleted
True iff IRangeQuery.DELETED semantics will be applied (that is, true if the caller wants to see the deleted tuples).


n

protected final int n
The #of source iterators.


sourceIterator

protected final I extends ITupleIterator<E>[] sourceIterator
The source iterators in the order given to the ctor.


sourceTuple

protected final ITuple<E>[] sourceTuple
The current ITuple from each source and null if we need to get another ITuple from that source. The value for a source iterator that has been exhausted will remain null. When all entries in this array are null there are no more ITuples to be visited and we are done.

Note: We process the iterators in the order given. Unless IRangeQuery.DELETED are being materialized we will only visit the ITuple for the first iterator having a entry for that key. This is achieved by setting the elements in this array to null for any iterator having a ITuple for the same key.


current

protected int current
Index into sourceIterator and sourceTuple of the iterator whose tuple will be returned next -or- -1 if we need to choose the next ITuple to be visited.


lastVisited

protected int lastVisited
The index into sourceIterator of the iterator whose tuple was last returned by next().

Constructor Detail

FusedTupleIterator

public FusedTupleIterator(int flags,
                          boolean deleted,
                          I[] sourceIterators)
Create an ITupleIterator reading from an ordered set of source ITupleIterators. The order of the source iterators is important. The first matching ITuple for a key will be the ITuple that gets returned. Other ITuples for the same key will be from source iterators later in the precedence order will be silently skipped.

Parameters:
flags - The flags specified for the source iterators (it is up to the caller to make sure that the same flags were used for all iterators).
deleted - false unless you want to see the deleted tuples in your application.
sourceIterators - Each source iterator MUST specify IRangeQuery.DELETED. This is NOT optional. The IRangeQuery.DELETED is required for the fused view iterator to recognize a deleted index entry and discard a historical undeleted entry later in the predence order for the view.
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<ITuple<E>>

next

public ITuple<E> next()
Description copied from interface: ITupleIterator
Advance the iterator and return the ITuple from which you can extract the data and metadata for next entry.

Note: An ITupleIterators will generally return the same ITuple reference on on each invocation of this method. The caller is responsible for copying out any data or metadata of interest before calling ITupleIterator.next() again. See TupleFilter which is aware of this and can be used to stack filters safely.

Specified by:
next in interface ITupleIterator<E>
Specified by:
next in interface Iterator<ITuple<E>>
Returns:
The ITuple containing the data and metadata for the current index entry.

consumeLookaheadTuple

protected ITuple<E> consumeLookaheadTuple()
Consume the current source ITuple.

Returns:
The current tuple.

clearCurrent

protected void clearCurrent()

Clear tuples from other sources having the same key as the current tuple.

If any source has the same key then we clear it's tuple since we have already returned a tuple for that key. This is necessary in order for the aggregate iterator to skip over additional tuples in other source streams once we identify a source stream having a tuple for a given key.

TODO:
if we wanted to see duplicate tuples when reading from sources that are NOT a FusedView then an additional flag could be introduced to the ctor and this method could be modified to NOT skip over the tuples whose key is EQ to the current key.

remove

public void remove()
Operation is not supported.

Note: Remove is not supported at this level. Instead you must use a FusedTupleCursor. This is handled automatically by FusedView.rangeIterator(byte[], byte[], int, int, com.bigdata.btree.filter.IFilterConstructor).

Specified by:
remove in interface Iterator<ITuple<E>>
Throws:
UnsupportedOperationException - always.


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.