use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class ColumnSliceFilterTest method testNullStart.
@Test
public void testNullStart() throws IOException {
ColumnSliceFilter.setSlice(is, null, "20080204");
columnSliceFilter.validateOptions(is.getOptions());
columnSliceFilter.init(new SortedMapIterator(TEST_DATA), is.getOptions(), iteratorEnvironment);
columnSliceFilter.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(columnSliceFilter.hasTop());
assertTrue(columnSliceFilter.getTopKey().equals(KEY_2));
columnSliceFilter.next();
assertTrue(columnSliceFilter.hasTop());
assertTrue(columnSliceFilter.getTopKey().equals(KEY_1));
columnSliceFilter.next();
assertTrue(columnSliceFilter.hasTop());
assertTrue(columnSliceFilter.getTopKey().equals(KEY_3));
columnSliceFilter.next();
assertTrue(columnSliceFilter.hasTop());
assertTrue(columnSliceFilter.getTopKey().equals(KEY_6));
columnSliceFilter.next();
assertFalse(columnSliceFilter.hasTop());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RowFilterTest method deepCopyCopiesTheSource.
@Test
public void deepCopyCopiesTheSource() throws Exception {
SortedMapIterator source = new SortedMapIterator(createKeyValues());
RowFilter filter = new RowZeroOrOneFilter();
filter.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
filter.seek(new Range(), Collections.emptySet(), false);
// Save off the first key and value
Key firstKey = filter.getTopKey();
Value firstValue = filter.getTopValue();
// Assert that the row is valid given our filter
assertEquals("0", firstKey.getRow().toString());
// Read some extra data, just making sure it's all valid
Key lastKeyRead = null;
for (int i = 0; i < 5; i++) {
filter.next();
lastKeyRead = filter.getTopKey();
assertEquals("0", lastKeyRead.getRow().toString());
}
// Make a copy of the original RowFilter
RowFilter copy = (RowFilter) filter.deepCopy(new DefaultIteratorEnvironment());
// Because it's a copy, we should be able to safely seek this one without affecting the original
copy.seek(new Range(), Collections.emptySet(), false);
assertTrue("deepCopy'ed RowFilter did not have a top key", copy.hasTop());
Key firstKeyFromCopy = copy.getTopKey();
Value firstValueFromCopy = copy.getTopValue();
// Verify that we got the same first k-v pair we did earlier
assertEquals(firstKey, firstKeyFromCopy);
assertEquals(firstValue, firstValueFromCopy);
filter.next();
Key finalKeyRead = filter.getTopKey();
// Make sure we got a Key that was greater than the last Key we read from the original RowFilter
assertTrue("Expected next key read to be greater than the previous after deepCopy", lastKeyRead.compareTo(finalKeyRead) < 0);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RowFilterTest method testChainedRowFilters.
@Test
public void testChainedRowFilters() throws Exception {
SortedMapIterator source = new SortedMapIterator(createKeyValues());
RowFilter filter0 = new TrueFilter();
filter0.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
RowFilter filter = new TrueFilter();
filter.init(filter0, Collections.emptyMap(), new DefaultIteratorEnvironment());
filter.seek(new Range(), Collections.emptySet(), false);
assertEquals(new HashSet<>(Arrays.asList("0", "1", "2", "3", "4")), getRows(filter));
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class TestCfCqSlice method testStackedFilters.
@Test
public void testStackedFilters() throws Exception {
Map<String, String> firstOpts = new HashMap<>();
Map<String, String> secondOpts = new HashMap<>();
boolean[][][] foundKvs = new boolean[LR_DIM][LR_DIM][LR_DIM];
long sliceMinCf = 20;
long sliceMaxCf = 25;
long sliceMinCq = 30;
long sliceMaxCq = 35;
assertTrue("slice param must be less than LR_DIM", sliceMinCf < LR_DIM);
assertTrue("slice param must be less than LR_DIM", sliceMinCq < LR_DIM);
assertTrue("slice param must be less than LR_DIM", sliceMaxCf < LR_DIM);
assertTrue("slice param must be less than LR_DIM", sliceMaxCq < LR_DIM);
firstOpts.put(CfCqSliceOpts.OPT_MIN_CF, new String(LONG_LEX.encode(sliceMinCf), UTF_8));
firstOpts.put(CfCqSliceOpts.OPT_MAX_CF, new String(LONG_LEX.encode(sliceMaxCf), UTF_8));
secondOpts.put(CfCqSliceOpts.OPT_MIN_CQ, new String(LONG_LEX.encode(sliceMinCq), UTF_8));
secondOpts.put(CfCqSliceOpts.OPT_MAX_CQ, new String(LONG_LEX.encode(sliceMaxCq), UTF_8));
SortedKeyValueIterator<Key, Value> skvi = getFilterClass().newInstance();
skvi.init(new SortedMapIterator(data), firstOpts, null);
loadKvs(skvi.deepCopy(null), foundKvs, secondOpts, INFINITY);
for (int i = 0; i < LR_DIM; i++) {
for (int j = 0; j < LR_DIM; j++) {
for (int k = 0; k < LR_DIM; k++) {
if (j >= sliceMinCf && j <= sliceMaxCf && k >= sliceMinCq && k <= sliceMaxCq) {
assertTrue("(r, cf, cq) == (" + i + ", " + j + ", " + k + ") must be found in scan", foundKvs[i][j][k]);
} else {
assertFalse("(r, cf, cq) == (" + i + ", " + j + ", " + k + ") must not be found in scan", foundKvs[i][j][k]);
}
}
}
}
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class VersioningIteratorTest method test2.
@Test
public void test2() {
Text colf = new Text("a");
Text colq = new Text("b");
TreeMap<Key, Value> tm = new TreeMap<>();
createTestData(tm, colf, colq);
try {
VersioningIterator it = new VersioningIterator();
IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
VersioningIterator.setMaxVersions(is, 3);
it.init(new SortedMapIterator(tm), is.getOptions(), null);
// after doing this seek, should only get two keys for row 1
// since we are seeking to the middle of the most recent
// three keys
Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 18);
it.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
TreeMap<Key, Value> tmOut = iteratorOverTestData(it);
for (Entry<Key, Value> e : tmOut.entrySet()) {
assertTrue(e.getValue().get().length == 8);
assertTrue(16 < encoder.decode(e.getValue().get()));
}
assertTrue("size after keeping 2 versions was " + tmOut.size(), tmOut.size() == 2);
} catch (IOException e) {
assertFalse(true);
} catch (Exception e) {
log.error("{}", e.getMessage(), e);
assertFalse(true);
}
}
Aggregations