Author: kturner
Date: Thu Jan 17 16:33:47 2013
New Revision: 1434768
URL: http://svn.apache.org/viewvc?rev=1434768&view=rev
Log:
ACCUMULO-956 formatted source code
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/user/KeyTransformingIterator.java
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/iterators/user/KeyTransformingIteratorTest.java
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/user/KeyTransformingIterator.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/user/KeyTransformingIterator.java?rev=1434768&r1=1434767&r2=1434768&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/user/KeyTransformingIterator.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/iterators/user/KeyTransformingIterator.java
Thu Jan 17 16:33:47 2013
@@ -45,49 +45,30 @@ import org.apache.hadoop.io.Text;
import org.apache.log4j.Logger;
/**
- * The KeyTransformingIterator allows portions of a key (except for the row)
- * to be transformed. This iterator handles the details that come with
modifying
- * keys (i.e., that the sort order could change). In order to do so, however,
- * the iterator must put all keys sharing the same prefix in memory. Prefix
- * is defined as the parts of the key that are not modified by this iterator.
- * That is, if the iterator modifies column qualifier and timestamp, then the
- * prefix is row and column family. In that case, the iterator must load all
- * column qualifiers for each row/column family pair into memory. Given this
- * constraint, care must be taken by users of this iterator to ensure it is
- * not run in such a way that will overrun memory in a tablet server.
+ * The KeyTransformingIterator allows portions of a key (except for the row)
to be transformed. This iterator handles the details that come with modifying
keys
+ * (i.e., that the sort order could change). In order to do so, however, the
iterator must put all keys sharing the same prefix in memory. Prefix is defined
as
+ * the parts of the key that are not modified by this iterator. That is, if
the iterator modifies column qualifier and timestamp, then the prefix is row and
+ * column family. In that case, the iterator must load all column qualifiers
for each row/column family pair into memory. Given this constraint, care must be
+ * taken by users of this iterator to ensure it is not run in such a way that
will overrun memory in a tablet server.
* <p>
- * If the implementing iterator is transforming column families, then it
- * must also override {@link #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 families, then it must
also override {@link #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).
* <p>
- * If the implementing iterator is transforming column visibilities, then
- * users must be careful NOT to fetch column qualifiers from the scanner.
- * The reason for this is due to ACCUMULO-??? (insert issue number).
+ * If the implementing iterator is transforming column visibilities, then
users must be careful NOT to fetch column qualifiers from the scanner. The
reason for
+ * this is due to ACCUMULO-??? (insert issue number).
* <p>
- * If the implementing iterator is transforming column visibilities, then the
- * user should be sure to supply authorizations via the {@link #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.
+ * If the implementing iterator is transforming column visibilities, then the
user should be sure to supply authorizations via the {@link #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.
*/
abstract public class KeyTransformingIterator extends WrappingIterator
implements OptionDescriber {
public static final String AUTH_OPT = "authorizations";
@@ -104,15 +85,14 @@ abstract public class KeyTransformingIte
private LRUMap visibleCache = null;
private LRUMap parsedVisibilitiesCache = null;
- private static Comparator<Pair<Key,Value>> keyComparator = new
Comparator<Pair<Key,Value>>() {
+ private static Comparator<Pair<Key,Value>> keyComparator = new
Comparator<Pair<Key,Value>>() {
@Override
public int compare(Pair<Key,Value> o1, Pair<Key,Value> o2) {
return o1.getFirst().compareTo(o2.getFirst());
}
};
- public KeyTransformingIterator() {
- }
+ public KeyTransformingIterator() {}
@Override
public void init(SortedKeyValueIterator<Key,Value> source,
Map<String,String> options, IteratorEnvironment env) throws IOException {
@@ -132,8 +112,8 @@ abstract public class KeyTransformingIte
@Override
public IteratorOptions describeOptions() {
String desc = "This iterator allows keys to be transformed.";
- String authDesc = "Comma-separated list of user's scan authorizations. " +
- "If excluded or empty, then no visibility check is performed on
transformed keys.";
+ String authDesc = "Comma-separated list of user's scan authorizations. "
+ + "If excluded or empty, then no visibility check is performed on
transformed keys.";
return new IteratorOptions(getClass().getSimpleName(), desc,
Collections.singletonMap(AUTH_OPT, authDesc), null);
}
@@ -195,14 +175,14 @@ abstract public class KeyTransformingIte
// Move on to the next entry since we returned the entry at keyPos before
if (keyPos >= 0)
keyPos++;
-
- // If we emptied out the transformed key map then transform the next key
- // set from the source. Itâs possible that transformation could produce
keys
+
+ // If we emptied out the transformed key map then transform the next key
+ // set from the source. Itâs possible that transformation could produce
keys
// that are outside of our range or are not visible to the end user, so
after the
- // call below we might not have added any keys to the map. Keep going
until
+ // call below we might not have added any keys to the map. Keep going until
// we either get some keys in the map or exhaust the source iterator.
while (!hasTop() && super.hasTop())
- transformKeys();
+ transformKeys();
}
@Override
@@ -212,7 +192,7 @@ abstract public class KeyTransformingIte
seekColumnFamiliesInclusive = inclusive;
// Seek the source iterator, but use a recalculated range that ensures
- // we see all keys with the same "prefix." We need to do this since
+ // we see all keys with the same "prefix." We need to do this since
// transforming could change the sort order and transformed keys that
// are before the range start could be inside the range after
transformation.
super.seek(computeReseekRange(range),
untransformColumnFamilies(columnFamilies), inclusive);
@@ -220,9 +200,9 @@ abstract public class KeyTransformingIte
// Range clipping could cause us to trim out all the keys we transformed.
// Keep looping until we either have some keys in the output range, or have
// exhausted the source iterator.
- keyPos = -1; // âClearâ list so hasTop returns false to get us into
the loop (transformKeys actually clears)
+ keyPos = -1; // âClearâ list so hasTop returns false to get us into
the loop (transformKeys actually clears)
while (!hasTop() && super.hasTop()) {
- // Build up a sorted list of all keys for the same prefix. When
+ // Build up a sorted list of all keys for the same prefix. When
// people ask for keys, return from this list first until it is empty
// before incrementing the source iterator.
transformKeys();
@@ -230,10 +210,8 @@ abstract public class KeyTransformingIte
}
/**
- * 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.
+ * 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.
*/
protected void transformKeys() throws IOException {
keyPos = -1;
@@ -244,7 +222,7 @@ abstract public class KeyTransformingIte
Key sourceTopKey = super.getTopKey();
// If the source key equals our prefix key (up to the prefix), then
- // we have a key that needs transformed. Otherwise, we're done.
+ // we have a key that needs transformed. Otherwise, we're done.
if (sourceTopKey.equals(prefixKey, getKeyPrefix())) {
Key transformedKey = transformKey(sourceTopKey);
@@ -256,7 +234,7 @@ abstract public class KeyTransformingIte
// in the key prefix here...
// Transformation could have produced a key that falls outside
- // of the seek range, or one that the user cannot see. Check
+ // of the seek range, or one that the user cannot see. Check
// these before adding it to the output list.
if (includeTransformedKey(transformedKey))
keys.add(new Pair<Key,Value>(transformedKey, new
Value(super.getTopValue())));
@@ -274,17 +252,13 @@ abstract public class KeyTransformingIte
}
/**
- * Determines whether or not to include {@code transformedKey} in 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.
+ * Determines whether or not to include {@code transformedKey} in 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.
*
- * @param transformedKey the key to check
+ * @param transformedKey
+ * the key to check
* @return {@code true} if the key should be included and {@code false} if
not
*/
protected boolean includeTransformedKey(Key transformedKey) {
@@ -296,17 +270,13 @@ abstract public class KeyTransformingIte
}
/**
- * Indicates whether or not the user is able to see {@code key}. If the
- * user has not supplied authorizations, or the iterator is not in the
- * scan scope, then this method simply returns {@code true}. Otherwise,
- * {@code 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.
+ * Indicates whether or not the user is able to see {@code key}. If the user
has not supplied authorizations, or the iterator is not in the scan scope, then
+ * this method simply returns {@code true}. Otherwise, {@code 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.
*
- * @param key the key to test
- * @return {@code true} if the key is visible or iterator is not scanning,
- * and {@code false} if not
+ * @param key
+ * the key to test
+ * @return {@code true} if the key is visible or iterator is not scanning,
and {@code false} if not
*/
protected boolean canSee(Key key) {
// Ensure that the visibility (which could have been transformed) parses.
@@ -344,12 +314,11 @@ abstract public class KeyTransformingIte
}
/**
- * Indicates whether or not {@code key} can be seen, according to the
- * fetched column families for this iterator.
+ * Indicates whether or not {@code key} can be seen, according to the
fetched column families for this iterator.
*
- * @param key the key whose column family is to be tested
- * @return {@code true} if {@code key}'s column family is one of those
fetched
- * in the set passed to our {@link #seek(Range, Collection,
boolean)} method
+ * @param key
+ * the key whose column family is to be tested
+ * @return {@code true} if {@code key}'s column family is one of those
fetched in the set passed to our {@link #seek(Range, Collection, boolean)}
method
*/
protected boolean canSeeColumnFamily(Key key) {
boolean visible = true;
@@ -364,12 +333,11 @@ abstract public class KeyTransformingIte
}
/**
- * Possibly expand {@code range} to 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.
+ * Possibly expand {@code range} to 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.
*
- * @param range the range to expand
+ * @param range
+ * the range to expand
* @return the modified range
*/
protected Range computeReseekRange(Range range) {
@@ -391,18 +359,18 @@ abstract public class KeyTransformingIte
}
/**
- * Indicates whether or not any part of {@code key} excluding
- * {@code part} is 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 on {@code key}.
+ * Indicates whether or not any part of {@code key} excluding {@code part}
is 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 on
{@code key}.
*
- * @param key the key to check
- * @param part the part of the key that doesn't need to be checked
(everything after does)
+ * @param key
+ * the key to check
+ * @param part
+ * the part of the key that doesn't need to be checked (everything
after does)
* @return {@code true} if anything after {@code part} is set on {@code
key}, and {@code false} if not
*/
protected boolean isSetAfterPart(Key key, PartialKey part) {
boolean isSet = false;
- if (key != null) {
+ if (key != null) {
// Breaks excluded on purpose.
switch (part) {
case ROW:
@@ -423,13 +391,13 @@ abstract public class KeyTransformingIte
}
/**
- * Creates a copy of {@code key}, copying only the parts of the key specified
- * in {@code part}. For example, if {@code part} is ROW_COLFAM_COLQUAL, then
- * this method would copy the row, column family, and column qualifier from
- * {@code key} into a new key.
+ * Creates a copy of {@code key}, copying only the parts of the key
specified in {@code part}. For example, if {@code part} is ROW_COLFAM_COLQUAL,
then this
+ * method would copy the row, column family, and column qualifier from
{@code key} into a new key.
*
- * @param key the key to copy
- * @param part the parts of {@code key} to copy
+ * @param key
+ * the key to copy
+ * @param part
+ * the parts of {@code key} to copy
* @return the new key containing {@code part} of {@code key}
*/
protected Key copyPartialKey(Key key, PartialKey part) {
@@ -448,8 +416,7 @@ abstract public class KeyTransformingIte
keyCopy = new Key(key.getRow(), key.getColumnFamily(),
key.getColumnQualifier(), key.getColumnVisibility());
break;
case ROW_COLFAM_COLQUAL_COLVIS_TIME:
- keyCopy = new Key(key.getRow(), key.getColumnFamily(),
key.getColumnQualifier(),
- key.getColumnVisibility(), key.getTimestamp());
+ keyCopy = new Key(key.getRow(), key.getColumnFamily(),
key.getColumnQualifier(), key.getColumnVisibility(), key.getTimestamp());
break;
default:
throw new IllegalArgumentException("Unsupported key part: " + part);
@@ -458,8 +425,7 @@ abstract public class KeyTransformingIte
}
/**
- * Make a new key with all parts (including delete flag) coming from {@code
originalKey} but
- * use {@code newColFam} as the column family.
+ * Make a new key with all parts (including delete flag) coming from {@code
originalKey} but use {@code newColFam} as the column family.
*/
protected Key replaceColumnFamily(Key originalKey, Text newColFam) {
byte[] row = originalKey.getRowData().toArray();
@@ -467,18 +433,13 @@ abstract public class KeyTransformingIte
byte[] cq = originalKey.getColumnQualifierData().toArray();
byte[] cv = originalKey.getColumnVisibilityData().toArray();
long timestamp = originalKey.getTimestamp();
- Key newKey = new Key(row, 0, row.length,
- cf, 0, newColFam.getLength(),
- cq, 0, cq.length,
- cv, 0, cv.length,
- timestamp);
+ Key newKey = new Key(row, 0, row.length, cf, 0, newColFam.getLength(), cq,
0, cq.length, cv, 0, cv.length, timestamp);
newKey.setDeleted(originalKey.isDeleted());
return newKey;
}
/**
- * Make a new key with all parts (including delete flag) coming from {@code
originalKey} but
- * use {@code newColQual} as the column qualifier.
+ * Make a new key with all parts (including delete flag) coming from {@code
originalKey} but use {@code newColQual} as the column qualifier.
*/
protected Key replaceColumnQualifier(Key originalKey, Text newColQual) {
byte[] row = originalKey.getRowData().toArray();
@@ -486,18 +447,13 @@ abstract public class KeyTransformingIte
byte[] cq = newColQual.getBytes();
byte[] cv = originalKey.getColumnVisibilityData().toArray();
long timestamp = originalKey.getTimestamp();
- Key newKey = new Key(row, 0, row.length,
- cf, 0, cf.length,
- cq, 0, newColQual.getLength(),
- cv, 0, cv.length,
- timestamp);
+ Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0,
newColQual.getLength(), cv, 0, cv.length, timestamp);
newKey.setDeleted(originalKey.isDeleted());
return newKey;
}
/**
- * Make a new key with all parts (including delete flag) coming from {@code
originalKey} but
- * use {@code newColVis} as the column visibility.
+ * Make a new key with all parts (including delete flag) coming from {@code
originalKey} but use {@code newColVis} as the column visibility.
*/
protected Key replaceColumnVisibility(Key originalKey, Text newColVis) {
byte[] row = originalKey.getRowData().toArray();
@@ -505,18 +461,14 @@ abstract public class KeyTransformingIte
byte[] cq = originalKey.getColumnQualifierData().toArray();
byte[] cv = newColVis.getBytes();
long timestamp = originalKey.getTimestamp();
- Key newKey = new Key(row, 0, row.length,
- cf, 0, cf.length,
- cq, 0, cq.length,
- cv, 0, newColVis.getLength(),
- timestamp);
+ Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0,
cq.length, cv, 0, newColVis.getLength(), timestamp);
newKey.setDeleted(originalKey.isDeleted());
return newKey;
}
/**
- * 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) from {@code
originalKey}.
+ * 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) from
+ * {@code originalKey}.
*/
protected Key replaceKeyParts(Key originalKey, Text newColFam, Text
newColQual, Text newColVis) {
byte[] row = originalKey.getRowData().toArray();
@@ -524,18 +476,13 @@ abstract public class KeyTransformingIte
byte[] cq = newColQual.getBytes();
byte[] cv = newColVis.getBytes();
long timestamp = originalKey.getTimestamp();
- Key newKey = new Key(row, 0, row.length,
- cf, 0, newColFam.getLength(),
- cq, 0, newColQual.getLength(),
- cv, 0, newColVis.getLength(),
- timestamp);
+ Key newKey = new Key(row, 0, row.length, cf, 0, newColFam.getLength(), cq,
0, newColQual.getLength(), cv, 0, newColVis.getLength(), timestamp);
newKey.setDeleted(originalKey.isDeleted());
return newKey;
}
/**
- * Make a new key with a column qualifier, and column visibility. Copy the
rest
- * of the parts of the key (including delete flag) from {@code originalKey}.
+ * Make a new key with a column qualifier, and column visibility. Copy the
rest of the parts of the key (including delete flag) from {@code originalKey}.
*/
protected Key replaceKeyParts(Key originalKey, Text newColQual, Text
newColVis) {
byte[] row = originalKey.getRowData().toArray();
@@ -543,24 +490,18 @@ abstract public class KeyTransformingIte
byte[] cq = newColQual.getBytes();
byte[] cv = newColVis.getBytes();
long timestamp = originalKey.getTimestamp();
- Key newKey = new Key(row, 0, row.length,
- cf, 0, cf.length,
- cq, 0, newColQual.getLength(),
- cv, 0, newColVis.getLength(),
- timestamp);
+ Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0,
newColQual.getLength(), cv, 0, newColVis.getLength(), timestamp);
newKey.setDeleted(originalKey.isDeleted());
return newKey;
}
/**
- * 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.
+ * 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.
*
- * @param columnFamilies the column families that have been fetched at seek
time
+ * @param columnFamilies
+ * the column families that have been fetched at seek time
* @return the untransformed column families that would transform info
{@code columnFamilies}
*/
protected Collection<ByteSequence>
untransformColumnFamilies(Collection<ByteSequence> columnFamilies) {
@@ -568,26 +509,21 @@ abstract public class KeyTransformingIte
}
/**
- * Indicates the prefix of keys that will be transformed by this iterator.
- * In other words, this is the part of the key that will <i>not</i> be
- * transformed by this iterator. For example, if this method returns
- * ROW_COLFAM, then {@link #transformKey(Key)} may be changing the
- * column qualifier, column visibility, or timestamp, but it won't be
- * changing the row or column family.
- *
+ * Indicates the prefix of keys that will be transformed by this iterator.
In other words, this is the part of the key that will <i>not</i> be transformed
by
+ * this iterator. For example, if this method returns ROW_COLFAM, then
{@link #transformKey(Key)} may be changing the column qualifier, column
visibility, or
+ * timestamp, but it won't be changing the row or column family.
+ *
* @return the part of the key this iterator is not transforming
*/
abstract protected PartialKey getKeyPrefix();
/**
- * Transforms {@code originalKey}. This method must not change the row
- * part of the key, and must only change the parts of the key after the
- * return value of {@link #getKeyPrefix()}. Implementors must also remember
- * to copy the delete flag from {@code originalKey} onto the new key. Or,
- * implementors should use one of the helper methods to produce the new
- * key. See any of the replaceKeyParts methods.
+ * Transforms {@code originalKey}. This method must not change the row part
of the key, and must only change the parts of the key after the return value of
+ * {@link #getKeyPrefix()}. Implementors must also remember to copy the
delete flag from {@code originalKey} onto the new key. Or, implementors should
use one
+ * of the helper methods to produce the new key. See any of the
replaceKeyParts methods.
*
- * @param originalKey the key to be transformed
+ * @param originalKey
+ * the key to be transformed
* @return the modified key
* @see #replaceColumnFamily(Key, Text)
* @see #replaceColumnQualifier(Key, Text)
Modified:
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/iterators/user/KeyTransformingIteratorTest.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/iterators/user/KeyTransformingIteratorTest.java?rev=1434768&r1=1434767&r2=1434768&view=diff
==============================================================================
---
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/iterators/user/KeyTransformingIteratorTest.java
(original)
+++
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/iterators/user/KeyTransformingIteratorTest.java
Thu Jan 17 16:33:47 2013
@@ -91,10 +91,10 @@ public class KeyTransformingIteratorTest
@Test
public void testIdentityScan() throws Exception {
- setUpTransformIterator(IdentityKeyTransformingIterator.class);
+ setUpTransformIterator(IdentityKeyTransformingIterator.class);
// This is just an identity scan, but with the "reuse" iterator that reuses
- // the same key/value pair for every getTopKey/getTopValue call. The code
+ // the same key/value pair for every getTopKey/getTopValue call. The code
// will always return the final key/value if we didn't copy the original
key
// in the iterator.
TreeMap<Key,Value> expected = new TreeMap<Key,Value>();
@@ -114,7 +114,8 @@ public class KeyTransformingIteratorTest
@Test
public void testNoRangeScan() throws Exception {
@SuppressWarnings("unchecked")
- List<Class<? extends ReversingKeyTransformingIterator>> classes =
Arrays.asList(ColFamReversingKeyTransformingIterator.class,
ColQualReversingKeyTransformingIterator.class,
ColVisReversingKeyTransformingIterator.class);
+ List<Class<? extends ReversingKeyTransformingIterator>> classes =
Arrays.asList(ColFamReversingKeyTransformingIterator.class,
+ ColQualReversingKeyTransformingIterator.class,
ColVisReversingKeyTransformingIterator.class);
// Test transforming col fam, col qual, col vis
for (Class<? extends ReversingKeyTransformingIterator> clazz : classes) {
@@ -134,14 +135,14 @@ public class KeyTransformingIteratorTest
}
}
- checkExpected(expected);
+ checkExpected(expected);
}
}
@Test
public void testVisbilityFiltering() throws Exception {
// Should return nothing since we produced visibilities that can't be seen
- setUpTransformIterator(BadVisKeyTransformingIterator.class);
+ setUpTransformIterator(BadVisKeyTransformingIterator.class);
checkExpected(new TreeMap<Key,Value>());
// Do a "reverse" on the visibility (vis1 -> vis2, vis2 -> vis3, vis3 ->
vis0)
@@ -159,13 +160,13 @@ public class KeyTransformingIteratorTest
}
}
}
- }
+ }
checkExpected(expected);
}
@Test
public void testRangeStart() throws Exception {
- setUpTransformIterator(ColVisReversingKeyTransformingIterator.class);
+ setUpTransformIterator(ColVisReversingKeyTransformingIterator.class);
scanner.setRange(new Range(new Key("row1", "cf2", "cq2", "vis1"), true,
new Key("row1", "cf2", "cq3"), false));
TreeMap<Key,Value> expected = new TreeMap<Key,Value>();
@@ -177,11 +178,11 @@ public class KeyTransformingIteratorTest
@Test
public void testRangeEnd() throws Exception {
- setUpTransformIterator(ColVisReversingKeyTransformingIterator.class);
+ setUpTransformIterator(ColVisReversingKeyTransformingIterator.class);
scanner.setRange(new Range(new Key("row1", "cf2", "cq2"), true, new
Key("row1", "cf2", "cq2", "vis2"), false));
TreeMap<Key,Value> expected = new TreeMap<Key,Value>();
- //putExpected(expected, 1, 2, 2, 1, part); // transforms vis outside range
end
+ // putExpected(expected, 1, 2, 2, 1, part); // transforms vis outside
range end
putExpected(expected, 1, 2, 2, 2, PartialKey.ROW_COLFAM_COLQUAL);
putExpected(expected, 1, 2, 2, 3, PartialKey.ROW_COLFAM_COLQUAL);
@@ -191,7 +192,7 @@ public class KeyTransformingIteratorTest
@Test
public void testPrefixRange() throws Exception {
setUpTransformIterator(ColFamReversingKeyTransformingIterator.class);
- // Set a range that is before all of the untransformed data. However,
+ // Set a range that is before all of the untransformed data. However,
// the data with untransformed col fam cf3 will transform to cf0 and
// be inside the range.
scanner.setRange(new Range(new Key("row1", "cf0"), true, new Key("row1",
"cf1"), false));
@@ -219,25 +220,25 @@ public class KeyTransformingIteratorTest
originalKey.setDeleted(true);
Key newKey = it.replaceColumnFamily(originalKey, new Text("test"));
- assertEquals(createDeleteKey("r","test","cq","cv",42), newKey);
+ assertEquals(createDeleteKey("r", "test", "cq", "cv", 42), newKey);
newKey = it.replaceColumnQualifier(originalKey, new Text("test"));
- assertEquals(createDeleteKey("r","cf","test","cv",42), newKey);
+ assertEquals(createDeleteKey("r", "cf", "test", "cv", 42), newKey);
newKey = it.replaceColumnVisibility(originalKey, new Text("test"));
- assertEquals(createDeleteKey("r","cf","cq","test",42), newKey);
+ assertEquals(createDeleteKey("r", "cf", "cq", "test", 42), newKey);
newKey = it.replaceKeyParts(originalKey, new Text("testCQ"), new
Text("testCV"));
- assertEquals(createDeleteKey("r","cf","testCQ","testCV",42), newKey);
+ assertEquals(createDeleteKey("r", "cf", "testCQ", "testCV", 42), newKey);
newKey = it.replaceKeyParts(originalKey, new Text("testCF"), new
Text("testCQ"), new Text("testCV"));
- assertEquals(createDeleteKey("r","testCF","testCQ","testCV",42), newKey);
+ assertEquals(createDeleteKey("r", "testCF", "testCQ", "testCV", 42),
newKey);
}
@Test
public void testFetchColumnFamilites() throws Exception {
// In this test, we are fetching column family cf2, which is in
- // the transformed space. The source column family that will
+ // the transformed space. The source column family that will
// transform into cf2 is cf1, so that is the column family we
// put in the expectations.
int expectedCF = 1;
@@ -260,7 +261,7 @@ public class KeyTransformingIteratorTest
@Test
public void testCompactionScanFetchingColumnFamilies() throws Exception {
// In this test, we are fetching column family cf2, which is in
- // the transformed space. The source column family that will
+ // the transformed space. The source column family that will
// transform into cf2 is cf1, so that is the column family we
// put in the expectations.
int expectedCF = 1;
@@ -273,15 +274,15 @@ public class KeyTransformingIteratorTest
for (int cv = 1; cv <= 3; ++cv)
putExpected(expected, row, expectedCF, cq, cv, PartialKey.ROW);
checkExpected(expected);
- }
+ }
@Test
public void testCompactionDoesntFilterVisibilities() throws Exception {
// In scan mode, this should return nothing since it produces visibilites
- // the user can't see. In compaction mode, however, the visibilites
+ // the user can't see. In compaction mode, however, the visibilites
// should still show up.
- setUpTransformIterator(BadVisCompactionKeyTransformingIterator.class);
-
+ setUpTransformIterator(BadVisCompactionKeyTransformingIterator.class);
+
TreeMap<Key,Value> expected = new TreeMap<Key,Value>();
for (int rowID = 1; rowID <= 3; ++rowID) {
for (int cfID = 1; cfID <= 3; ++cfID) {
@@ -291,7 +292,7 @@ public class KeyTransformingIteratorTest
String cf = "cf" + cfID;
String cq = "cq" + cqID;
String cv = "badvis";
- long ts = 100*cfID + 10*cqID + cvID;
+ long ts = 100 * cfID + 10 * cqID + cvID;
String val = "val" + ts;
expected.put(new Key(row, cf, cq, cv, ts), new
Value(val.getBytes()));
}
@@ -299,7 +300,7 @@ public class KeyTransformingIteratorTest
}
}
- checkExpected(expected);
+ checkExpected(expected);
}
private Key createDeleteKey(String row, String colFam, String colQual,
String colVis, long timestamp) {
@@ -327,17 +328,20 @@ public class KeyTransformingIteratorTest
String cf = "cf" + cfID;
String cq = "cq" + cqID;
String cv = "vis" + cvID;
- long ts = 100*cfID + 10*cqID + cvID;
+ long ts = 100 * cfID + 10 * cqID + cvID;
String val = "val" + ts;
if (part != null) {
switch (part) {
case ROW:
- cf = transform(new Text(cf)).toString(); break;
+ cf = transform(new Text(cf)).toString();
+ break;
case ROW_COLFAM:
- cq = transform(new Text(cq)).toString(); break;
+ cq = transform(new Text(cq)).toString();
+ break;
case ROW_COLFAM_COLQUAL:
- cv = transform(new Text(cv)).toString(); break;
+ cv = transform(new Text(cv)).toString();
+ break;
default:
break;
}
@@ -349,7 +353,7 @@ public class KeyTransformingIteratorTest
private static Text transform(Text val) {
String s = val.toString();
// Reverse the order of the number at the end, and subtract one
- int i = 3 - Integer.parseInt(s.substring(s.length()-1));
+ int i = 3 - Integer.parseInt(s.substring(s.length() - 1));
StringBuilder sb = new StringBuilder();
sb.append(s.substring(0, s.length() - 1));
sb.append(i);
@@ -364,7 +368,7 @@ public class KeyTransformingIteratorTest
String cf = "cf" + cfID;
String cq = "cq" + cqID;
String cv = "vis" + cvID;
- long ts = 100*cfID + 10*cqID + cvID;
+ long ts = 100 * cfID + 10 * cqID + cvID;
String val = "val" + ts;
m.put(cf, cq, new ColumnVisibility(cv), ts, val);
@@ -382,11 +386,14 @@ public class KeyTransformingIteratorTest
long ts = originalKey.getTimestamp();
switch (part) {
case ROW:
- cf = transform(cf); break;
+ cf = transform(cf);
+ break;
case ROW_COLFAM:
- cq = transform(cq); break;
+ cq = transform(cq);
+ break;
case ROW_COLFAM_COLQUAL:
- cv = transform(cv); break;
+ cv = transform(cv);
+ break;
default:
break;
}
@@ -421,7 +428,7 @@ public class KeyTransformingIteratorTest
@Override
protected Collection<ByteSequence>
untransformColumnFamilies(Collection<ByteSequence> columnFamilies) {
HashSet<ByteSequence> untransformed = new HashSet<ByteSequence>();
- for (ByteSequence cf : columnFamilies)
+ for (ByteSequence cf : columnFamilies)
untransformed.add(untransformColumnFamily(cf));
return untransformed;
}
@@ -515,23 +522,23 @@ public class KeyTransformingIteratorTest
public MajCIteratorEnvironmentAdapter(IteratorEnvironment delegate) {
this.delegate = delegate;
}
-
+
public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String
mapFileName) throws IOException {
return delegate.reserveMapFileReader(mapFileName);
}
-
+
public AccumuloConfiguration getConfig() {
return delegate.getConfig();
}
-
+
public IteratorScope getIteratorScope() {
return IteratorScope.majc;
}
-
+
public boolean isFullMajorCompaction() {
return delegate.isFullMajorCompaction();
}
-
+
public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
delegate.registerSideChannel(iter);
}