use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class RowFilterTest method testFilterConjunction.
@Test
public void testFilterConjunction() throws Exception {
SortedMapIterator source = new SortedMapIterator(createKeyValues());
RowFilter filter0 = new RowZeroOrOneFilter();
filter0.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
RowFilter filter = new RowOneOrTwoFilter();
filter.init(filter0, Collections.emptyMap(), new DefaultIteratorEnvironment());
filter.seek(new Range(), Collections.emptySet(), false);
assertEquals(Set.of("1"), getRows(filter));
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class TransformingIteratorTest method setUpTransformIterator.
private void setUpTransformIterator(Class<? extends TransformingIterator> clazz, boolean setupAuths) throws IOException {
SortedMapIterator source = new SortedMapIterator(data);
ColumnFamilySkippingIterator cfsi = new ColumnFamilySkippingIterator(source);
SortedKeyValueIterator<Key, Value> visFilter = VisibilityFilter.wrap(cfsi, authorizations, new byte[0]);
ReuseIterator reuserIter = new ReuseIterator();
reuserIter.init(visFilter, EMPTY_OPTS, null);
try {
titer = clazz.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
IteratorEnvironment iterEnv = EasyMock.createMock(IteratorEnvironment.class);
EasyMock.expect(iterEnv.getIteratorScope()).andReturn(IteratorScope.scan).anyTimes();
EasyMock.replay(iterEnv);
Map<String, String> opts;
if (setupAuths) {
IteratorSetting cfg = new IteratorSetting(21, clazz);
TransformingIterator.setAuthorizations(cfg, new Authorizations("vis0", "vis1", "vis2", "vis3"));
opts = cfg.getOptions();
} else {
opts = Map.of();
}
titer.init(reuserIter, opts, iterEnv);
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class VisibilityFilterTest method verify.
private void verify(TreeMap<Key, Value> source, int expectedSourceSize, Map<String, String> options, Text expectedCF, Text expectedCQ, Text expectedCV, int expectedFinalCount) throws IOException {
assertEquals(expectedSourceSize, source.size());
Filter filter = new VisibilityFilter();
filter.init(new SortedMapIterator(source), options, null);
filter.seek(new Range(), EMPTY_COL_FAMS, false);
int count = 0;
while (filter.hasTop()) {
count++;
// System.out.println(DefaultFormatter.formatEntry(
// Collections.singletonMap(filter.getTopKey(),
// filter.getTopValue()).entrySet().iterator().next(),
// false));
assertEquals(expectedCF, filter.getTopKey().getColumnFamily());
assertEquals(expectedCQ, filter.getTopKey().getColumnQualifier());
assertEquals(expectedCV, filter.getTopKey().getColumnVisibility());
filter.next();
}
assertEquals(expectedFinalCount, count);
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class WholeRowIteratorTest method testContinue.
@Test
public void testContinue() throws Exception {
SortedMap<Key, Value> map1 = new TreeMap<>();
pkv(map1, "row1", "cf1", "cq1", "cv1", 5, "foo");
pkv(map1, "row1", "cf1", "cq2", "cv1", 6, "bar");
SortedMap<Key, Value> map2 = new TreeMap<>();
pkv(map2, "row2", "cf1", "cq1", "cv1", 5, "foo");
pkv(map2, "row2", "cf1", "cq2", "cv1", 6, "bar");
SortedMap<Key, Value> map3 = new TreeMap<>();
pkv(map3, "row3", "cf1", "cq1", "cv1", 5, "foo");
pkv(map3, "row3", "cf1", "cq2", "cv1", 6, "bar");
SortedMap<Key, Value> map = new TreeMap<>();
map.putAll(map1);
map.putAll(map2);
map.putAll(map3);
SortedMapIterator source = new SortedMapIterator(map);
WholeRowIterator iter = new WholeRowIterator(source);
Range range = new Range(new Text("row1"), true, new Text("row2"), true);
iter.seek(range, new ArrayList<>(), false);
assertTrue(iter.hasTop());
assertEquals(map1, WholeRowIterator.decodeRow(iter.getTopKey(), iter.getTopValue()));
// simulate something continuing using the last key from the iterator
// this is what client and server code will do
range = new Range(iter.getTopKey(), false, range.getEndKey(), range.isEndKeyInclusive());
iter.seek(range, new ArrayList<>(), false);
assertTrue(iter.hasTop());
assertEquals(map2, WholeRowIterator.decodeRow(iter.getTopKey(), iter.getTopValue()));
iter.next();
assertFalse(iter.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class CombinerTest method testDeepCopy.
@Test
public void testDeepCopy() throws IOException {
Encoder<Long> encoder = LongCombiner.FIXED_LEN_ENCODER;
TreeMap<Key, Value> tm1 = new TreeMap<>();
// keys that aggregate
newKeyValue(tm1, 1, 1, 1, 1, false, 2L, encoder);
newKeyValue(tm1, 1, 1, 1, 2, false, 3L, encoder);
newKeyValue(tm1, 1, 1, 1, 3, false, 4L, encoder);
// keys that do not aggregate
newKeyValue(tm1, 2, 2, 1, 1, false, 2L, encoder);
newKeyValue(tm1, 2, 2, 1, 2, false, 3L, encoder);
Combiner ai = new SummingCombiner();
IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
LongCombiner.setEncodingType(is, FixedLenEncoder.class.getName());
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
SortedKeyValueIterator<Key, Value> ai2 = ai.deepCopy(null);
SortedKeyValueIterator<Key, Value> ai3 = ai.deepCopy(null);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(2, 2, 1, 1), ai.getTopKey());
assertEquals("2", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
// seek after key that aggregates
ai2.seek(newRow(1, 1, 1, 2), EMPTY_COL_FAMS, false);
assertTrue(ai2.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai2.getTopKey());
assertEquals("3", encoder.decode(ai2.getTopValue().get()).toString());
// seek before key that aggregates
ai3.seek(newRow(1, 1, 1, 4), EMPTY_COL_FAMS, false);
assertTrue(ai3.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai3.getTopKey());
assertEquals("9", encoder.decode(ai3.getTopValue().get()).toString());
ai3.next();
assertTrue(ai3.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai3.getTopKey());
assertEquals("3", encoder.decode(ai3.getTopValue().get()).toString());
}
Aggregations