Class TransformingIterator
- All Implemented Interfaces:
OptionDescriber,SortedKeyValueIterator<Key,,Value> YieldingKeyValueIterator<Key,Value>
If the implementing iterator is transforming column families, then it must also override
untransformColumnFamilies(Collection) to handle the case when column families are fetched
at scan time. The fetched column families will/must be in the transformed space, and the
untransformed column families need to be passed to this iterator's source. If it is not possible
to write a reverse transformation (e.g., the column family transformation depends on the row
value or something like that), then the iterator must not fetch specific column families (or only
fetch column families that are known to not transform at all).
If the implementing iterator is transforming column visibilities, then users must be careful NOT to fetch column qualifiers from the scanner.
If the implementing iterator is transforming column visibilities, then the user should be sure to
supply authorizations via the AUTH_OPT iterator option (note that this is only necessary
for scan scope iterators). The supplied authorizations should be in the transformed space, but
the authorizations supplied to the scanner should be in the untransformed space. That is, if the
iterator transforms A to 1, B to 2, C to 3, etc, then the auths supplied when the scanner is
constructed should be A,B,C,... and the auths supplied to the iterator should be 1,2,3,... The
reason for this is that the scanner performs security filtering before this iterator is called,
so the authorizations need to be in the original untransformed space. Since the iterator can
transform visibilities, it is possible that it could produce visibilities that the user cannot
see, so the transformed keys must be tested to ensure the user is allowed to view them. Note that
this test is not necessary when the iterator is not used in the scan scope since no security
filtering is performed during major and minor compactions. It should also be noted that this
iterator implements the security filtering rather than relying on a follow-on iterator to do it
so that we ensure the test is performed.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.apache.accumulo.core.iterators.OptionDescriber
OptionDescriber.IteratorOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected intstatic final Stringprotected booleanprotected Collection<ByteSequence>protected booleanprotected Range -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanIndicates whether or not the user is able to seekey.protected booleancanSeeColumnFamily(Key key) Indicates whether or notkeycan be seen, according to the fetched column families for this iterator.protected RangecomputeReseekRange(Range range) Possibly expandrangeto include everything for the key prefix we are working with.protected KeycopyPartialKey(Key key, PartialKey part) Creates a copy ofkey, copying only the parts of the key specified inpart.Creates a deep copy of this iterator as though seek had not yet been called.Gets an iterator options object that contains information needed to configure this iterator.protected abstract PartialKeyIndicates the prefix of keys that will be transformed by this iterator.Returns top key.Returns top value.booleanhasTop()Returns true if the iterator has more elements.protected booleanincludeTransformedKey(Key transformedKey) Determines whether or not to includetransformedKeyin the output.voidinit(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) Initializes the iterator.protected booleanisSetAfterPart(Key key, PartialKey part) Indicates whether or not any part ofkeyexcludingpartis set.voidnext()Advances to the next K,V pair.protected KeyreplaceColumnFamily(Key originalKey, org.apache.hadoop.io.Text newColFam) Make a new key with all parts (including delete flag) coming fromoriginalKeybut usenewColFamas the column family.protected KeyreplaceColumnQualifier(Key originalKey, org.apache.hadoop.io.Text newColQual) Make a new key with all parts (including delete flag) coming fromoriginalKeybut usenewColQualas the column qualifier.protected KeyreplaceColumnVisibility(Key originalKey, org.apache.hadoop.io.Text newColVis) Make a new key with all parts (including delete flag) coming fromoriginalKeybut usenewColVisas the column visibility.protected KeyreplaceKeyParts(Key originalKey, org.apache.hadoop.io.Text newColQual, org.apache.hadoop.io.Text newColVis) Make a new key with a column qualifier, and column visibility.protected KeyreplaceKeyParts(Key originalKey, org.apache.hadoop.io.Text newColFam, org.apache.hadoop.io.Text newColQual, org.apache.hadoop.io.Text newColVis) Make a new key with a column family, column qualifier, and column visibility.voidseek(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.static voidsetAuthorizations(IteratorSetting config, Authorizations auths) Configure authorizations used for post transformation filtering.static voidsetMaxBufferSize(IteratorSetting config, long maxBufferSize) Configure the maximum amount of memory that can be used for transformation.protected voidReads all keys matching the first key's prefix from the source iterator, transforms them, and sorts the resulting keys.protected abstract voidtransformRange(SortedKeyValueIterator<Key, Value> input, TransformingIterator.KVBuffer output) Transformsinput.protected Collection<ByteSequence>untransformColumnFamilies(Collection<ByteSequence> columnFamilies) Reverses the transformation applied to column families that are fetched at seek time.booleanvalidateOptions(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 org.apache.accumulo.core.iterators.WrappingIterator
getSource, setSourceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.accumulo.core.iterators.YieldingKeyValueIterator
enableYielding
-
Field Details
-
AUTH_OPT
- See Also:
-
MAX_BUFFER_SIZE_OPT
- See Also:
-
keys
-
keyPos
protected int keyPos -
scanning
protected boolean scanning -
seekRange
-
seekColumnFamilies
-
seekColumnFamiliesInclusive
protected boolean seekColumnFamiliesInclusive
-
-
Constructor Details
-
TransformingIterator
public TransformingIterator()
-
-
Method Details
-
init
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, throws IOExceptionString> options, IteratorEnvironment env) Description copied from interface:SortedKeyValueIteratorInitializes the iterator. Data should not be read from the source in this method.- Specified by:
initin interfaceSortedKeyValueIterator<Key,Value> - Overrides:
initin classWrappingIterator- Parameters:
source-SortedKeyValueIteratorsource to read data from.options-Mapmap of string option names to option values.env-IteratorEnvironmentenvironment in which iterator is being run, provided by Accumulo itself and is expected to be non-null.- Throws:
IOException- unused.
-
describeOptions
Description copied from interface:OptionDescriberGets 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:
describeOptionsin interfaceOptionDescriber- Returns:
- an iterator options object
-
validateOptions
Description copied from interface:OptionDescriberCheck 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:
validateOptionsin interfaceOptionDescriber- Parameters:
options- a map of option names to option values- Returns:
- true if options are valid, false otherwise (IllegalArgumentException preferred)
-
deepCopy
Description copied from interface:SortedKeyValueIteratorCreates 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. A proper implementation would call deepCopy on the source.- Specified by:
deepCopyin interfaceSortedKeyValueIterator<Key,Value> - Overrides:
deepCopyin classWrappingIterator- Parameters:
env-IteratorEnvironmentenvironment in which iterator is being run, provided by Accumulo itself and is expected to be non-null.- Returns:
SortedKeyValueIteratora copy of this iterator (with the same source and settings).
-
hasTop
public boolean hasTop()Description copied from interface:SortedKeyValueIteratorReturns true if the iterator has more elements. Note that if this iterator has yielded (@see YieldingKeyValueIterator.enableYielding(YieldCallback)), this this method must return false.- Specified by:
hasTopin interfaceSortedKeyValueIterator<Key,Value> - Overrides:
hasTopin classWrappingIterator- Returns:
trueif the iterator has more elements.
-
getTopKey
Description copied from interface:SortedKeyValueIteratorReturns 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.For performance reasons, iterators reserve the right to reuse objects returned by
getTopKeywhenSortedKeyValueIterator.next()is called, changing the data that the object references. Iterators that need to save an object returned bygetTopKeyought to copy the object's data into a new object in order to avoid aliasing bugs.- Specified by:
getTopKeyin interfaceSortedKeyValueIterator<Key,Value> - Overrides:
getTopKeyin classWrappingIterator- Returns:
K
-
getTopValue
Description copied from interface:SortedKeyValueIteratorReturns top value. Can be called 0 or more times without affecting behavior of next() or hasTop().For performance reasons, iterators reserve the right to reuse objects returned by
getTopValuewhenSortedKeyValueIterator.next()is called, changing the underlying data that the object references. Iterators that need to save an object returned bygetTopValueought to copy the object's data into a new object in order to avoid aliasing bugs.- Specified by:
getTopValuein interfaceSortedKeyValueIterator<Key,Value> - Overrides:
getTopValuein classWrappingIterator- Returns:
V
-
next
Description copied from interface:SortedKeyValueIteratorAdvances 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:
nextin interfaceSortedKeyValueIterator<Key,Value> - Overrides:
nextin classWrappingIterator- 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:SortedKeyValueIteratorSeeks 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 afterSortedKeyValueIterator.init(org.apache.accumulo.core.iterators.SortedKeyValueIterator<K, V>, java.util.Map<java.lang.String, java.lang.String>, 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.columnFamiliesis used, at the lowest level, to determine which data blocks inside of an RFile need to be opened for this iterator. This set of data blocks is also the set of locality groups defined for the given table. If no columnFamilies are provided, the data blocks for all locality groups inside of the correct RFile will be opened and seeked in an attempt to find the correct start key, regardless of the startKey in therange. In an Accumulo instance in which multiple locality groups exist for a table, it is important to ensure thatcolumnFamiliesis properly set to the minimum required column families to ensure that data from separate locality groups is not inadvertently read.- Specified by:
seekin interfaceSortedKeyValueIterator<Key,Value> - Overrides:
seekin classWrappingIterator- Parameters:
range-Rangeof keys to iterate over.columnFamilies-Collectionof column families to include or exclude.inclusive-booleanthat indicates whether to include (true) or exclude (false) column families.- Throws:
IOException- if an I/O error occurs.
-
transformKeys
Reads all keys matching the first key's prefix from the source iterator, transforms them, and sorts the resulting keys. Transformed keys that fall outside of our seek range or can't be seen by the user are excluded.- Throws:
IOException
-
includeTransformedKey
Determines whether or not to includetransformedKeyin the output. It is possible that transformation could have produced a key that falls outside of the seek range, a key with a visibility the user can't see, a key with a visibility that doesn't parse, or a key with a column family that wasn't fetched. We only do some checks (outside the range, user can see) if we're scanning. The range check is not done for major/minor compaction since seek ranges won't be in our transformed key space and we will never change the row so we can't produce keys that would fall outside the tablet anyway.- Parameters:
transformedKey- the key to check- Returns:
trueif the key should be included andfalseif not
-
canSee
Indicates whether or not the user is able to seekey. If the user has not supplied authorizations, or the iterator is not in the scan scope, then this method simply returnstrue. Otherwise,key's column visibility is tested against the user-supplied authorizations, and the test result is returned. For performance, the test results are cached so that the same visibility is not tested multiple times.- Parameters:
key- the key to test- Returns:
trueif the key is visible or iterator is not scanning, andfalseif not
-
canSeeColumnFamily
Indicates whether or notkeycan be seen, according to the fetched column families for this iterator.- Parameters:
key- the key whose column family is to be tested- Returns:
trueifkey's column family is one of those fetched in the set passed to ourseek(Range, Collection, boolean)method
-
computeReseekRange
Possibly expandrangeto include everything for the key prefix we are working with. That is, if our prefix is ROW_COLFAM, then we need to expand the range so we're sure to include all entries having the same row and column family as the start/end of the range.- Parameters:
range- the range to expand- Returns:
- the modified range
-
isSetAfterPart
Indicates whether or not any part ofkeyexcludingpartis set. For example, if part is ROW_COLFAM_COLQUAL, then this method determines whether or not the column visibility, timestamp, or delete flag is set onkey.- Parameters:
key- the key to checkpart- the part of the key that doesn't need to be checked (everything after does)- Returns:
trueif anything afterpartis set onkey, andfalseif not
-
copyPartialKey
Creates a copy ofkey, copying only the parts of the key specified inpart. For example, ifpartis ROW_COLFAM_COLQUAL, then this method would copy the row, column family, and column qualifier fromkeyinto a new key.- Parameters:
key- the key to copypart- the parts ofkeyto copy- Returns:
- the new key containing
partofkey
-
replaceColumnFamily
Make a new key with all parts (including delete flag) coming fromoriginalKeybut usenewColFamas the column family. -
replaceColumnQualifier
Make a new key with all parts (including delete flag) coming fromoriginalKeybut usenewColQualas the column qualifier. -
replaceColumnVisibility
Make a new key with all parts (including delete flag) coming fromoriginalKeybut usenewColVisas the column visibility. -
replaceKeyParts
protected Key replaceKeyParts(Key originalKey, org.apache.hadoop.io.Text newColFam, org.apache.hadoop.io.Text newColQual, org.apache.hadoop.io.Text newColVis) Make a new key with a column family, column qualifier, and column visibility. Copy the rest of the parts of the key (including delete flag) fromoriginalKey. -
replaceKeyParts
protected Key replaceKeyParts(Key originalKey, org.apache.hadoop.io.Text newColQual, org.apache.hadoop.io.Text newColVis) Make a new key with a column qualifier, and column visibility. Copy the rest of the parts of the key (including delete flag) fromoriginalKey. -
untransformColumnFamilies
protected Collection<ByteSequence> untransformColumnFamilies(Collection<ByteSequence> columnFamilies) Reverses the transformation applied to column families that are fetched at seek time. If this iterator is transforming column families, then this method should be overridden to reverse the transformation on the supplied collection of column families. This is necessary since the fetch/seek will be performed in the transformed space, but when passing the column family set on to the source, the column families need to be in the untransformed space.- Parameters:
columnFamilies- the column families that have been fetched at seek time- Returns:
- the untransformed column families that would transform info
columnFamilies
-
getKeyPrefix
Indicates the prefix of keys that will be transformed by this iterator. In other words, this is the part of the key that will not be transformed by this iterator. For example, if this method returns ROW_COLFAM, thentransformKeys()may be changing the column qualifier, column visibility, or timestamp, but it won't be changing the row or column family.- Returns:
- the part of the key this iterator is not transforming
-
transformRange
protected abstract void transformRange(SortedKeyValueIterator<Key, Value> input, TransformingIterator.KVBuffer output) throws IOExceptionTransformsinput. This method must not change the row part of the key, and must only change the parts of the key after the return value ofgetKeyPrefix(). Implementors must also remember to copy the delete flag fromoriginalKeyonto the new key. Or, implementors should use one of the helper methods to produce the new key. See any of the replaceKeyParts methods.- Parameters:
input- An iterator over a group of keys with the same prefix. This iterator provides an efficient view, bounded by the prefix, of the underlying iterator and can not be seeked.output- An output buffer that holds transformed key values. All key values added to the buffer must have the same prefix as the input keys.- Throws:
IOException- See Also:
-
setAuthorizations
Configure authorizations used for post transformation filtering. -
setMaxBufferSize
Configure the maximum amount of memory that can be used for transformation. If this memory is exceeded an exception will be thrown.- Parameters:
maxBufferSize- size in bytes
-