org.apache.accumulo.examples.wikisearch.iterator
Class AndIterator

java.lang.Object
  extended by org.apache.accumulo.examples.wikisearch.iterator.AndIterator
All Implemented Interfaces:
SortedKeyValueIterator<Key,Value>

public class AndIterator
extends Object
implements SortedKeyValueIterator<Key,Value>


Nested Class Summary
protected static class AndIterator.TermSource
          Used in representing a Term that is intersected on.
 
Field Summary
static String columnFamiliesOptionName
           
protected  byte[] emptyByteArray
           
protected static org.apache.log4j.Logger log
           
static String notFlagsOptionName
           
protected  org.apache.hadoop.io.Text nullText
           
static String termValuesOptionName
           
protected  Value value
           
 
Constructor Summary
AndIterator()
          Empty default constructor
AndIterator(AndIterator other, IteratorEnvironment env)
           
 
Method Summary
 void addSource(SortedKeyValueIterator<Key,Value> source, IteratorEnvironment env, org.apache.hadoop.io.Text term, boolean notFlag)
           
 void addSource(SortedKeyValueIterator<Key,Value> source, IteratorEnvironment env, org.apache.hadoop.io.Text dataLocation, org.apache.hadoop.io.Text term, boolean notFlag)
           
protected  void advanceToIntersection()
           
protected  Key buildFollowingPartitionKey(Key key)
          Return the key that directly follows the given key
protected  Key buildKey(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text dataLocation)
          Build a key from the given row and dataLocation
protected  Key buildKey(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text dataLocation, org.apache.hadoop.io.Text term)
          Build a key from the given row, dataLocation, and term
static boolean[] decodeBooleans(String flags)
          Decode the encoded NOT flags into a boolean array
static org.apache.hadoop.io.Text[] decodeColumns(String columns)
          Decode the encoded columns into a Text array
static org.apache.hadoop.io.Text[] decodeTermValues(String terms)
          Decode the encoded terms into a Text array
 SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env)
          Creates a deep copy of this iterator as though seek had not yet been called.
static String encodeBooleans(boolean[] flags)
          Encode an array of booleans denoted which columns are NOT'ed
static String encodeColumns(org.apache.hadoop.io.Text[] columns)
          Encode a Text array of all the columns to intersect on
static String encodeTermValues(org.apache.hadoop.io.Text[] terms)
          Encode a Text array of all of the terms to intersect on.
protected  org.apache.hadoop.io.Text getDataLocation(Key key)
          Returns the given key's dataLocation
protected  org.apache.hadoop.io.Text getDocID(Key key)
          Returns the given key's DocID
protected  org.apache.hadoop.io.Text getPartition(Key key)
           
protected  org.apache.hadoop.io.Text getTerm(Key key)
          Returns the given key's term
 Key getTopKey()
          Returns top key.
 Value getTopValue()
          Returns top value.
protected  String getUID(Key key)
          Returns the given key's UID
 boolean hasTop()
          Returns true if the iterator has more elements.
 void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env)
          Initializes the iterator.
 boolean jump(Key jumpKey)
           
 void next()
          Advances to the next K,V pair.
 void seek(Range range, Collection<ByteSequence> seekColumnFamilies, boolean inclusive)
          Seeks to the first key in the Range, restricting the resulting K,V pairs to those with the specified columns.
static String stringTopKey(SortedKeyValueIterator<Key,Value> iter)
           
 
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

nullText

protected org.apache.hadoop.io.Text nullText

emptyByteArray

protected final byte[] emptyByteArray

value

protected Value value

columnFamiliesOptionName

public static final String columnFamiliesOptionName
See Also:
Constant Field Values

termValuesOptionName

public static final String termValuesOptionName
See Also:
Constant Field Values

notFlagsOptionName

public static final String notFlagsOptionName
See Also:
Constant Field Values
Constructor Detail

AndIterator

public AndIterator()
Empty default constructor


AndIterator

public AndIterator(AndIterator other,
                   IteratorEnvironment env)
Method Detail

getPartition

protected org.apache.hadoop.io.Text getPartition(Key key)

getDataLocation

protected org.apache.hadoop.io.Text getDataLocation(Key key)
Returns the given key's dataLocation

Parameters:
key -
Returns:
The given key's dataLocation

getTerm

protected org.apache.hadoop.io.Text getTerm(Key key)
Returns the given key's term

Parameters:
key -
Returns:
The given key's term

getDocID

protected org.apache.hadoop.io.Text getDocID(Key key)
Returns the given key's DocID

Parameters:
key -
Returns:
The given key's DocID

getUID

protected String getUID(Key key)
Returns the given key's UID

Parameters:
key -
Returns:
The given key's UID

buildKey

protected Key buildKey(org.apache.hadoop.io.Text row,
                       org.apache.hadoop.io.Text dataLocation)
Build a key from the given row and dataLocation

Parameters:
row - The desired row
dataLocation - The desired dataLocation
Returns:
A Key object built from the given row and dataLocation.

buildKey

protected Key buildKey(org.apache.hadoop.io.Text row,
                       org.apache.hadoop.io.Text dataLocation,
                       org.apache.hadoop.io.Text term)
Build a key from the given row, dataLocation, and term

Parameters:
row - The desired row
dataLocation - The desired dataLocation
term - The desired term
Returns:
A Key object built from the given row, dataLocation, and term.

buildFollowingPartitionKey

protected Key buildFollowingPartitionKey(Key key)
Return the key that directly follows the given key

Parameters:
key - The key who will be directly before the returned key
Returns:
The key directly following the given key.

deepCopy

public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env)
Description copied from interface: SortedKeyValueIterator
Creates a deep copy of this iterator as though seek had not yet been called. init should be called on an iterator before deepCopy is called. init should not need to be called on the copy that is returned by deepCopy; that is, when necessary init should be called in the deepCopy method on the iterator it returns. The behavior is unspecified if init is called after deepCopy either on the original or the copy.

Specified by:
deepCopy in interface SortedKeyValueIterator<Key,Value>
Parameters:
env - IteratorEnvironment environment in which iterator is being run.
Returns:
SortedKeyValueIterator a copy of this iterator (with the same source and settings).

getTopKey

public Key getTopKey()
Description copied from interface: SortedKeyValueIterator
Returns top key. Can be called 0 or more times without affecting behavior of next() or hasTop(). Note that in minor compaction scope and in non-full major compaction scopes the iterator may see deletion entries. These entries should be preserved by all iterators except ones that are strictly scan-time iterators that will never be configured for the minc or majc scopes. Deletion entries are only removed during full major compactions.

Specified by:
getTopKey in interface SortedKeyValueIterator<Key,Value>
Returns:
K

getTopValue

public Value getTopValue()
Description copied from interface: SortedKeyValueIterator
Returns top value. Can be called 0 or more times without affecting behavior of next() or hasTop().

Specified by:
getTopValue in interface SortedKeyValueIterator<Key,Value>
Returns:
V

hasTop

public boolean hasTop()
Description copied from interface: SortedKeyValueIterator
Returns true if the iterator has more elements.

Specified by:
hasTop in interface SortedKeyValueIterator<Key,Value>
Returns:
true if the iterator has more elements.

next

public void next()
          throws IOException
Description copied from interface: SortedKeyValueIterator
Advances to the next K,V pair. Note that in minor compaction scope and in non-full major compaction scopes the iterator may see deletion entries. These entries should be preserved by all iterators except ones that are strictly scan-time iterators that will never be configured for the minc or majc scopes. Deletion entries are only removed during full major compactions.

Specified by:
next in interface SortedKeyValueIterator<Key,Value>
Throws:
IOException - if an I/O error occurs.

advanceToIntersection

protected void advanceToIntersection()
                              throws IOException
Throws:
IOException

stringTopKey

public static String stringTopKey(SortedKeyValueIterator<Key,Value> iter)

encodeColumns

public static String encodeColumns(org.apache.hadoop.io.Text[] columns)
Encode a Text array of all the columns to intersect on

Parameters:
columns - The columns to be encoded
Returns:
A Base64 encoded string (using a \n delimiter) of all columns to intersect on.

encodeTermValues

public static String encodeTermValues(org.apache.hadoop.io.Text[] terms)
Encode a Text array of all of the terms to intersect on. The terms should match the columns in a one-to-one manner

Parameters:
terms - The terms to be encoded
Returns:
A Base64 encoded string (using a \n delimiter) of all terms to intersect on.

encodeBooleans

public static String encodeBooleans(boolean[] flags)
Encode an array of booleans denoted which columns are NOT'ed

Parameters:
flags - The array of NOTs
Returns:
A base64 encoded string of which columns are NOT'ed

decodeColumns

public static org.apache.hadoop.io.Text[] decodeColumns(String columns)
Decode the encoded columns into a Text array

Parameters:
columns - The Base64 encoded String of the columns
Returns:
A Text array of the decoded columns

decodeTermValues

public static org.apache.hadoop.io.Text[] decodeTermValues(String terms)
Decode the encoded terms into a Text array

Parameters:
terms - The Base64 encoded String of the terms
Returns:
A Text array of decoded terms.

decodeBooleans

public static boolean[] decodeBooleans(String flags)
Decode the encoded NOT flags into a boolean array

Parameters:
flags -
Returns:
A boolean array of decoded NOT flags

init

public void init(SortedKeyValueIterator<Key,Value> source,
                 Map<String,String> options,
                 IteratorEnvironment env)
          throws IOException
Description copied from interface: SortedKeyValueIterator
Initializes the iterator. Data should not be read from the source in this method.

Specified by:
init in interface SortedKeyValueIterator<Key,Value>
Parameters:
source - SortedKeyValueIterator source to read data from.
options - Map map of string option names to option values.
env - IteratorEnvironment environment in which iterator is being run.
Throws:
IOException - unused.

seek

public void seek(Range range,
                 Collection<ByteSequence> seekColumnFamilies,
                 boolean inclusive)
          throws IOException
Description copied from interface: SortedKeyValueIterator
Seeks to the first key in the Range, restricting the resulting K,V pairs to those with the specified columns. An iterator does not have to stop at the end of the range. The whole range is provided so that iterators can make optimizations. Seek may be called multiple times with different parameters after SortedKeyValueIterator.init(org.apache.accumulo.core.iterators.SortedKeyValueIterator, java.util.Map, org.apache.accumulo.core.iterators.IteratorEnvironment) is called. Iterators that examine groups of adjacent key/value pairs (e.g. rows) to determine their top key and value should be sure that they properly handle a seek to a key in the middle of such a group (e.g. the middle of a row). Even if the client always seeks to a range containing an entire group (a,c), the tablet server could send back a batch of entries corresponding to (a,b], then reseek the iterator to range (b,c) when the scan is continued.

Specified by:
seek in interface SortedKeyValueIterator<Key,Value>
Parameters:
range - Range of keys to iterate over.
seekColumnFamilies - Collection of column families to include or exclude.
inclusive - boolean that indicates whether to include (true) or exclude (false) column families.
Throws:
IOException - if an I/O error occurs.

addSource

public void addSource(SortedKeyValueIterator<Key,Value> source,
                      IteratorEnvironment env,
                      org.apache.hadoop.io.Text term,
                      boolean notFlag)

addSource

public void addSource(SortedKeyValueIterator<Key,Value> source,
                      IteratorEnvironment env,
                      org.apache.hadoop.io.Text dataLocation,
                      org.apache.hadoop.io.Text term,
                      boolean notFlag)

jump

public boolean jump(Key jumpKey)
             throws IOException
Throws:
IOException


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.