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

java.lang.Object
  extended by org.apache.accumulo.examples.wikisearch.iterator.AbstractEvaluatingIterator
All Implemented Interfaces:
OptionDescriber, SortedKeyValueIterator<Key,Value>
Direct Known Subclasses:
EvaluatingIterator

public abstract class AbstractEvaluatingIterator
extends Object
implements SortedKeyValueIterator<Key,Value>, OptionDescriber

This iterator aggregates rows together using the specified key comparator. Subclasses will provide their own implementation of fillMap which will fill the supplied EventFields object with field names (key) and field values (value). After all fields have been put into the aggregated object (by aggregating all columns with the same key), the EventFields object will be compared against the supplied expression. If the expression returns true, then the return key and return value can be retrieved via getTopKey() and getTopValue(). Optionally, the caller can set an expression (field operator value) that should not be evaluated against the event. For example, if the query is "A == 'foo' and B == 'bar'", but for some reason B may not be in the data, then setting the UNEVALUATED_EXPRESSIONS option to "B == 'bar'" will allow the events to be evaluated against the remainder of the expression and still return as true. By default this iterator will return all Events in the shard. If the START_DATE and END_DATE are specified, then this iterator will evaluate the timestamp of the key against the start and end dates. If the event date is not within the range of start to end, then it is skipped. This iterator will return up the stack an EventFields object serialized using Kryo in the cell Value.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.accumulo.core.iterators.OptionDescriber
OptionDescriber.IteratorOptions
 
Field Summary
protected  SortedKeyValueIterator<Key,Value> iterator
           
protected static byte[] NULL_BYTE
           
static String QUERY_OPTION
           
static String UNEVALUTED_EXPRESSIONS
           
 
Constructor Summary
  AbstractEvaluatingIterator()
           
protected AbstractEvaluatingIterator(AbstractEvaluatingIterator other, IteratorEnvironment env)
           
 
Method Summary
 OptionDescriber.IteratorOptions describeOptions()
          Gets an iterator options object that contains information needed to configure this iterator.
abstract  void fillMap(EventFields event, Key key, Value value)
          Implementations will need to fill the map with field visibilities, names, and values.
abstract  PartialKey getKeyComparator()
          Implementations will return the PartialKey value to use for comparing keys for aggregating events
 String getQueryExpression()
           
abstract  Key getReturnKey(Key k)
          When the query expression evaluates to true against the event, the event fields will be serialized into the Value and returned up the iterator stack.
 Key getTopKey()
          Returns top key.
 Value getTopValue()
          Returns top value.
 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.
abstract  boolean isKeyAccepted(Key key)
          Provides the ability to skip this key and all of the following ones that match using the comparator.
 void next()
          Advances to the next K,V pair.
 void reset()
          Reset state.
 void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
          Seeks to the first key in the Range, restricting the resulting K,V pairs to those with the specified columns.
 boolean validateOptions(Map<String,String> options)
          Check to see if an options map contains all options required by an iterator and that the option values are in the expected formats.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.accumulo.core.iterators.SortedKeyValueIterator
deepCopy
 

Field Detail

NULL_BYTE

protected static final byte[] NULL_BYTE

QUERY_OPTION

public static final String QUERY_OPTION
See Also:
Constant Field Values

UNEVALUTED_EXPRESSIONS

public static final String UNEVALUTED_EXPRESSIONS
See Also:
Constant Field Values

iterator

protected SortedKeyValueIterator<Key,Value> iterator
Constructor Detail

AbstractEvaluatingIterator

protected AbstractEvaluatingIterator(AbstractEvaluatingIterator other,
                                     IteratorEnvironment env)

AbstractEvaluatingIterator

public AbstractEvaluatingIterator()
Method Detail

getKeyComparator

public abstract PartialKey getKeyComparator()
Implementations will return the PartialKey value to use for comparing keys for aggregating events

Returns:
the type of comparator to use

getReturnKey

public abstract Key getReturnKey(Key k)
                          throws Exception
When the query expression evaluates to true against the event, the event fields will be serialized into the Value and returned up the iterator stack. Implemenations will need to provide a key to be used with the event.

Parameters:
k -
Returns:
the key that should be returned with the map of values.
Throws:
Exception

fillMap

public abstract void fillMap(EventFields event,
                             Key key,
                             Value value)
                      throws Exception
Implementations will need to fill the map with field visibilities, names, and values. When all fields have been aggregated the event will be evaluated against the query expression.

Parameters:
event - Multimap of event names and fields.
key - current Key
value - current Value
Throws:
Exception

isKeyAccepted

public abstract boolean isKeyAccepted(Key key)
                               throws IOException
Provides the ability to skip this key and all of the following ones that match using the comparator.

Parameters:
key -
Returns:
true if the key should be acted upon, otherwise false.
Throws:
IOException

reset

public void reset()
Reset state.


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.

seek

public void seek(Range range,
                 Collection<ByteSequence> columnFamilies,
                 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.
columnFamilies - 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.

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.

describeOptions

public OptionDescriber.IteratorOptions describeOptions()
Description copied from interface: OptionDescriber
Gets an iterator options object that contains information needed to configure this iterator. This object will be used by the accumulo shell to prompt the user to input the appropriate information.

Specified by:
describeOptions in interface OptionDescriber
Returns:
an iterator options object

validateOptions

public boolean validateOptions(Map<String,String> options)
Description copied from interface: OptionDescriber
Check to see if an options map contains all options required by an iterator and that the option values are in the expected formats.

Specified by:
validateOptions in interface OptionDescriber
Parameters:
options - a map of option names to option values
Returns:
true if options are valid, false otherwise

getQueryExpression

public String getQueryExpression()


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