use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class WholeRowIteratorTest method testEmptyStuff.
@Test
public void testEmptyStuff() throws IOException {
SortedMap<Key, Value> map = new TreeMap<>();
SortedMap<Key, Value> map2 = new TreeMap<>();
final Map<Text, Boolean> toInclude = new HashMap<>();
map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 1L), new Value("val1"));
map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq2"), new Text("cv1"), 2L), new Value("val2"));
map.put(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 3L), new Value("val3"));
map.put(new Key(new Text("r2"), new Text("cf2"), new Text("cq1"), new Text("cv1"), 4L), new Value("val4"));
map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 5L), new Value("val4"));
map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv2"), 6L), new Value("val4"));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 7L), new Value(""));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text(""), 8L), new Value("val1"));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text(""), new Text("cv1"), 9L), new Value("val1"));
map.put(new Key(new Text("r4"), new Text(""), new Text("cq1"), new Text("cv1"), 10L), new Value("val1"));
map.put(new Key(new Text(""), new Text("cf1"), new Text("cq1"), new Text("cv1"), 11L), new Value("val1"));
boolean b = true;
int trueCount = 0;
for (Key k : map.keySet()) {
if (toInclude.containsKey(k.getRow())) {
if (toInclude.get(k.getRow())) {
map2.put(k, map.get(k));
}
continue;
}
b = !b;
toInclude.put(k.getRow(), b);
if (b) {
trueCount++;
map2.put(k, map.get(k));
}
}
SortedMapIterator source = new SortedMapIterator(map);
WholeRowIterator iter = new WholeRowIterator(source);
SortedMap<Key, Value> resultMap = new TreeMap<>();
iter.seek(new Range(), new ArrayList<>(), false);
int numRows = 0;
while (iter.hasTop()) {
numRows++;
Key rowKey = iter.getTopKey();
Value rowValue = iter.getTopValue();
resultMap.putAll(WholeRowIterator.decodeRow(rowKey, rowValue));
iter.next();
}
assertEquals(5, numRows);
assertEquals(resultMap, map);
WholeRowIterator iter2 = new WholeRowIterator(source) {
@Override
public boolean filter(Text row, List<Key> keys, List<Value> values) {
return toInclude.get(row);
}
};
resultMap.clear();
iter2.seek(new Range(), new ArrayList<>(), false);
numRows = 0;
while (iter2.hasTop()) {
numRows++;
Key rowKey = iter2.getTopKey();
Value rowValue = iter2.getTopValue();
resultMap.putAll(WholeRowIterator.decodeRow(rowKey, rowValue));
iter2.next();
}
assertEquals(numRows, trueCount);
assertEquals(resultMap, map2);
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class CombinerTest method test7.
@Test
public void test7() throws IOException {
Encoder<Long> encoder = LongCombiner.FIXED_LEN_ENCODER;
// test that delete is not aggregated
TreeMap<Key, Value> tm1 = new TreeMap<>();
newKeyValue(tm1, 1, 1, 1, 2, true, 0L, encoder);
newKeyValue(tm1, 1, 1, 1, 3, false, 4L, encoder);
newKeyValue(tm1, 1, 1, 1, 4, false, 3L, encoder);
Combiner ai = new SummingCombiner();
IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
LongCombiner.setEncodingType(is, SummingCombiner.Type.FIXEDLEN);
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
ai.seek(newRow(1, 1, 1, 4, true), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 4), ai.getTopKey());
assertEquals("7", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 2, true), ai.getTopKey());
assertEquals("0", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
tm1 = new TreeMap<>();
newKeyValue(tm1, 1, 1, 1, 2, true, 0L, encoder);
ai = new SummingCombiner();
ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
ai.seek(newRow(1, 1, 1, 4, true), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 2, true), ai.getTopKey());
assertEquals("0", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class CombinerTest method valueIteratorTest.
@Test
public void valueIteratorTest() throws IOException {
TreeMap<Key, Value> tm = new TreeMap<>();
tm.put(new Key("r", "f", "q", 1), new Value("1"));
tm.put(new Key("r", "f", "q", 2), new Value("2"));
SortedMapIterator smi = new SortedMapIterator(tm);
smi.seek(new Range(), EMPTY_COL_FAMS, false);
ValueIterator iter = new ValueIterator(smi);
assertEquals(iter.next().toString(), "2");
assertEquals(iter.next().toString(), "1");
assertFalse(iter.hasNext());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class ColumnFilterTest method test3.
@Test
public void test3() throws Exception {
TreeMap<Key, Value> data = new TreeMap<>();
data.put(newKey("r1", "cf1", "cq1"), new Value(""));
data.put(newKey("r1", "cf2", "cq1"), new Value(""));
data.put(newKey("r1", "cf2", "cq2"), new Value(""));
HashSet<Column> columns = new HashSet<>();
columns.add(newColumn("cf2", "cq1"));
SortedKeyValueIterator<Key, Value> cf = ColumnQualifierFilter.wrap(new SortedMapIterator(data), columns);
cf.seek(new Range(), Collections.emptySet(), false);
assertTrue(cf.hasTop());
assertEquals(newKey("r1", "cf2", "cq1"), cf.getTopKey());
cf.next();
assertFalse(cf.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class MultiIteratorTest method test4.
@Test
public void test4() throws IOException {
// TEST empty input
TreeMap<Key, Value> tm1 = new TreeMap<>();
List<SortedKeyValueIterator<Key, Value>> skvil = new ArrayList<>(1);
skvil.add(new SortedMapIterator(tm1));
MultiIterator mi = new MultiIterator(skvil, true);
assertFalse(mi.hasTop());
mi.seek(newRange(0, 6), EMPTY_COL_FAMS, false);
assertFalse(mi.hasTop());
}
Aggregations