use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class WholeColumnFamilyIteratorTest 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);
WholeColumnFamilyIterator iter = new WholeColumnFamilyIterator(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(WholeColumnFamilyIterator.decodeColumnFamily(rowKey, rowValue));
iter.next();
}
// we have 7 groups of row key/cf
assertEquals(7, numRows);
assertEquals(resultMap, map);
WholeColumnFamilyIterator iter2 = new WholeColumnFamilyIterator(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(WholeColumnFamilyIterator.decodeColumnFamily(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 TimeSettingIteratorTest method test1.
@Test
public void test1() throws Exception {
TreeMap<Key, Value> tm1 = new TreeMap<>();
tm1.put(new Key("r0", "cf1", "cq1", 9L), new Value("v0"));
tm1.put(new Key("r1", "cf1", "cq1", Long.MAX_VALUE), new Value("v1"));
tm1.put(new Key("r1", "cf1", "cq1", 90L), new Value("v2"));
tm1.put(new Key("r1", "cf1", "cq1", 0L), new Value("v3"));
tm1.put(new Key("r2", "cf1", "cq1", 6L), new Value("v4"));
TimeSettingIterator tsi = new TimeSettingIterator(new SortedMapIterator(tm1), 50);
tsi.seek(new Range(new Key("r1", "cf1", "cq1", 50L), true, new Key("r1", "cf1", "cq1", 50L), true), new HashSet<>(), false);
assertTrue(tsi.hasTop());
assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v1", tsi.getTopValue().toString());
tsi.next();
assertTrue(tsi.hasTop());
assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v2", tsi.getTopValue().toString());
tsi.next();
assertTrue(tsi.hasTop());
assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v3", tsi.getTopValue().toString());
tsi.next();
assertFalse(tsi.hasTop());
tsi.seek(new Range(new Key("r1", "cf1", "cq1", 50L), false, null, true), new HashSet<>(), false);
assertTrue(tsi.hasTop());
assertEquals(new Key("r2", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v4", tsi.getTopValue().toString());
tsi.next();
assertFalse(tsi.hasTop());
tsi.seek(new Range(null, true, new Key("r1", "cf1", "cq1", 50L), false), new HashSet<>(), false);
assertTrue(tsi.hasTop());
assertEquals(new Key("r0", "cf1", "cq1", 50L), tsi.getTopKey());
assertEquals("v0", tsi.getTopValue().toString());
tsi.next();
assertFalse(tsi.hasTop());
tsi.seek(new Range(new Key("r1", "cf1", "cq1", 51L), true, new Key("r1", "cf1", "cq1", 50L), false), new HashSet<>(), false);
assertFalse(tsi.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class TimeSettingIteratorTest method testAvoidKeyCopy.
@Test
public void testAvoidKeyCopy() throws Exception {
TreeMap<Key, Value> tm1 = new TreeMap<>();
final Key k = new Key("r0", "cf1", "cq1", 9L);
tm1.put(k, new Value("v0"));
TimeSettingIterator tsi = new TimeSettingIterator(new SortedMapIterator(tm1), 50);
tsi.seek(new Range(), new HashSet<>(), false);
assertTrue(tsi.hasTop());
final Key topKey = tsi.getTopKey();
assertSame(k, topKey, "Expected the topKey to be the same object");
assertEquals(new Key("r0", "cf1", "cq1", 50L), topKey);
assertEquals("v0", tsi.getTopValue().toString());
tsi.next();
assertFalse(tsi.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class BigDecimalCombinerTest method testSums.
@Test
public void testSums() throws IOException {
ai = new BigDecimalCombiner.BigDecimalSummingCombiner();
IteratorSetting is = new IteratorSetting(1, BigDecimalCombiner.BigDecimalSummingCombiner.class);
Combiner.setColumns(is, columns);
ai.init(new SortedMapIterator(tm1), is.getOptions(), CombinerTest.SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(CombinerTest.newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals(-9.7, encoder.decode(ai.getTopValue().get()).doubleValue(), delta);
verify();
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class BigDecimalCombinerTest method testMin.
@Test
public void testMin() throws IOException {
ai = new BigDecimalCombiner.BigDecimalMinCombiner();
IteratorSetting is = new IteratorSetting(1, BigDecimalCombiner.BigDecimalMinCombiner.class);
Combiner.setColumns(is, columns);
ai.init(new SortedMapIterator(tm1), is.getOptions(), CombinerTest.SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(CombinerTest.newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals(-14.0, encoder.decode(ai.getTopValue().get()).doubleValue(), delta);
verify();
}
Aggregations