use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class CombinerTest method runDeleteHandlingTest.
private void runDeleteHandlingTest(TreeMap<Key, Value> input, TreeMap<Key, Value> expected, Boolean rofco, IteratorEnvironment env, boolean expectedLog, boolean clearLogMsgCache) throws Exception {
boolean deepCopy = expected == null;
if (clearLogMsgCache) {
CombinerTestUtil.clearLogCache();
}
Combiner ai = new SummingCombiner();
IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
SummingCombiner.setEncodingType(is, LongCombiner.StringEncoder.class);
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
if (rofco != null) {
Combiner.setReduceOnFullCompactionOnly(is, rofco);
}
ai.init(new SortedMapIterator(input), is.getOptions(), env);
if (deepCopy)
assertEquals(expected, readAll(ai.deepCopy(env)));
assertEquals(expected, readAll(ai));
long logSize = CombinerTestUtil.cacheSize();
if (expectedLog) {
assertTrue(logSize > 0, "Expected >0 log messages, but got : " + logSize);
} else {
assertEquals(0, logSize, "Expected 0 log messages, but got : " + logSize);
}
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class CombinerTest method test5.
@Test
public void test5() throws IOException {
Encoder<Long> encoder = LongCombiner.STRING_ENCODER;
// try aggregating across multiple data sets that contain
// the exact same keys w/ different values
TreeMap<Key, Value> tm1 = new TreeMap<>();
newKeyValue(tm1, 1, 1, 1, 1, false, 2L, encoder);
TreeMap<Key, Value> tm2 = new TreeMap<>();
newKeyValue(tm2, 1, 1, 1, 1, false, 3L, encoder);
TreeMap<Key, Value> tm3 = new TreeMap<>();
newKeyValue(tm3, 1, 1, 1, 1, false, 4L, encoder);
Combiner ai = new SummingCombiner();
IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
LongCombiner.setEncodingType(is, StringEncoder.class);
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
List<SortedKeyValueIterator<Key, Value>> sources = new ArrayList<>(3);
sources.add(new SortedMapIterator(tm1));
sources.add(new SortedMapIterator(tm2));
sources.add(new SortedMapIterator(tm3));
MultiIterator mi = new MultiIterator(sources, true);
ai.init(mi, is.getOptions(), SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 1), ai.getTopKey());
assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class RowEncodingIteratorTest method testEncodeSome.
@Test
public void testEncodeSome() throws IOException {
byte[] kbVal = new byte[1024];
// This code is shamelessly borrowed from the WholeRowIteratorTest.
SortedMap<Key, Value> map1 = new TreeMap<>();
pkv(map1, "row1", "cf1", "cq1", "cv1", 5, kbVal);
pkv(map1, "row1", "cf1", "cq2", "cv1", 6, kbVal);
SortedMap<Key, Value> map = new TreeMap<>();
map.putAll(map1);
SortedMapIterator src = new SortedMapIterator(map);
Range range = new Range(new Text("row1"), true, new Text("row2"), true);
RowEncodingIteratorImpl iter = new RowEncodingIteratorImpl();
Map<String, String> bigBufferOpts = new HashMap<>();
bigBufferOpts.put(RowEncodingIterator.MAX_BUFFER_SIZE_OPT, "1K");
iter.init(src, bigBufferOpts, new DummyIteratorEnv());
assertThrows(IllegalArgumentException.class, () -> iter.seek(range, new ArrayList<>(), false));
// IllegalArgumentException should be thrown as we can't fit the whole row into its buffer
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class RowEncodingIteratorTest method testEncodeAll.
@Test
public void testEncodeAll() throws IOException {
byte[] kbVal = new byte[1024];
// This code is shamelessly borrowed from the WholeRowIteratorTest.
SortedMap<Key, Value> map1 = new TreeMap<>();
pkv(map1, "row1", "cf1", "cq1", "cv1", 5, kbVal);
pkv(map1, "row1", "cf1", "cq2", "cv1", 6, kbVal);
SortedMap<Key, Value> map2 = new TreeMap<>();
pkv(map2, "row2", "cf1", "cq1", "cv1", 5, kbVal);
pkv(map2, "row2", "cf1", "cq2", "cv1", 6, kbVal);
SortedMap<Key, Value> map3 = new TreeMap<>();
pkv(map3, "row3", "cf1", "cq1", "cv1", 5, kbVal);
pkv(map3, "row3", "cf1", "cq2", "cv1", 6, kbVal);
SortedMap<Key, Value> map = new TreeMap<>();
map.putAll(map1);
map.putAll(map2);
map.putAll(map3);
SortedMapIterator src = new SortedMapIterator(map);
Range range = new Range(new Text("row1"), true, new Text("row2"), true);
RowEncodingIteratorImpl iter = new RowEncodingIteratorImpl();
Map<String, String> bigBufferOpts = new HashMap<>();
bigBufferOpts.put(RowEncodingIterator.MAX_BUFFER_SIZE_OPT, "3K");
iter.init(src, bigBufferOpts, new DummyIteratorEnv());
iter.seek(range, new ArrayList<>(), false);
assertTrue(iter.hasTop());
assertEquals(map1, RowEncodingIteratorImpl.decodeRow(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, RowEncodingIteratorImpl.decodeRow(iter.getTopValue()));
iter.next();
assertFalse(iter.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class FirstEntryInRowIteratorTest method process.
private static long process(TreeMap<Key, Value> sourceMap, TreeMap<Key, Value> resultMap, Range range, IteratorSetting iteratorSetting) throws IOException {
SortedMapIterator source = new SortedMapIterator(sourceMap);
CountingIterator counter = new CountingIterator(source);
FirstEntryInRowIterator feiri = new FirstEntryInRowIterator();
IteratorEnvironment env = new DefaultIteratorEnvironment();
feiri.init(counter, iteratorSetting.getOptions(), env);
feiri.seek(range, Set.of(), false);
while (feiri.hasTop()) {
resultMap.put(feiri.getTopKey(), feiri.getTopValue());
feiri.next();
}
return counter.getCount();
}
Aggregations