use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class WholeColumnFamilyIteratorTest method testEmptyStuff.
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".getBytes()));
map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq2"), new Text("cv1"), 2l), new Value("val2".getBytes()));
map.put(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 3l), new Value("val3".getBytes()));
map.put(new Key(new Text("r2"), new Text("cf2"), new Text("cq1"), new Text("cv1"), 4l), new Value("val4".getBytes()));
map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 5l), new Value("val4".getBytes()));
map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv2"), 6l), new Value("val4".getBytes()));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 7l), new Value("".getBytes()));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text(""), 8l), new Value("val1".getBytes()));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text(""), new Text("cv1"), 9l), new Value("val1".getBytes()));
map.put(new Key(new Text("r4"), new Text(""), new Text("cq1"), new Text("cv1"), 10l), new Value("val1".getBytes()));
map.put(new Key(new Text(""), new Text("cf1"), new Text("cq1"), new Text("cv1"), 11l), new Value("val1".getBytes()));
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
Assert.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();
}
assertTrue(numRows == trueCount);
assertEquals(resultMap, map2);
}
use of org.apache.accumulo.core.iterators.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.iterators.SortedMapIterator in project accumulo by apache.
the class ColumnFamilySkippingIteratorTest method test3.
public void test3() throws Exception {
// construct test where ColumnFamilySkippingIterator might try to seek past the end of the user supplied range
TreeMap<Key, Value> tm1 = new TreeMap<>();
for (int r = 0; r < 3; r++) {
for (int cf = 4; cf < 1000; cf++) {
for (int cq = 0; cq < 1; cq++) {
put(tm1, r, cf, cq, 6, r * cf * cq);
}
}
}
CountingIterator ci = new CountingIterator(new SortedMapIterator(tm1));
ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(ci);
HashSet<ByteSequence> colfams = new HashSet<>();
colfams.add(new ArrayByteSequence(String.format("%06d", 4)));
Range range = new Range(newKey(0, 4, 0, 6), true, newKey(0, 400, 0, 6), true);
cfi.seek(range, colfams, true);
assertTrue(cfi.hasTop());
assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
cfi.next();
assertFalse(cfi.hasTop());
colfams.add(new ArrayByteSequence(String.format("%06d", 500)));
cfi.seek(range, colfams, true);
assertTrue(cfi.hasTop());
assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
cfi.next();
assertFalse(cfi.hasTop());
range = new Range(newKey(0, 4, 0, 6), true, newKey(1, 400, 0, 6), true);
cfi.seek(range, colfams, true);
assertTrue(cfi.hasTop());
assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
cfi.next();
assertTrue(cfi.hasTop());
assertEquals(newKey(0, 500, 0, 6), cfi.getTopKey());
cfi.next();
assertTrue(cfi.hasTop());
assertEquals(newKey(1, 4, 0, 6), cfi.getTopKey());
cfi.next();
assertFalse(cfi.hasTop());
// System.out.println(ci.getCount());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class ColumnFamilySkippingIteratorTest method test2.
public void test2() throws Exception {
TreeMap<Key, Value> tm1 = new TreeMap<>();
for (int r = 0; r < 10; r++) {
for (int cf = 0; cf < 1000; cf++) {
for (int cq = 0; cq < 3; cq++) {
put(tm1, r, cf, cq, 6, r * cf * cq);
}
}
}
HashSet<ByteSequence> allColfams = new HashSet<>();
for (int cf = 0; cf < 1000; cf++) {
allColfams.add(new ArrayByteSequence(String.format("%06d", cf)));
}
ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(new SortedMapIterator(tm1));
HashSet<ByteSequence> colfams = new HashSet<>();
runTest(cfi, 30000, 0, allColfams, colfams);
colfams.add(new ArrayByteSequence(String.format("%06d", 60)));
runTest(cfi, 30000, 30, allColfams, colfams);
colfams.add(new ArrayByteSequence(String.format("%06d", 602)));
runTest(cfi, 30000, 60, allColfams, colfams);
colfams.add(new ArrayByteSequence(String.format("%06d", 0)));
runTest(cfi, 30000, 90, allColfams, colfams);
colfams.add(new ArrayByteSequence(String.format("%06d", 999)));
runTest(cfi, 30000, 120, allColfams, colfams);
colfams.remove(new ArrayByteSequence(String.format("%06d", 0)));
runTest(cfi, 30000, 90, allColfams, colfams);
colfams.add(new ArrayByteSequence(String.format("%06d", 1000)));
runTest(cfi, 30000, 90, allColfams, colfams);
colfams.remove(new ArrayByteSequence(String.format("%06d", 999)));
runTest(cfi, 30000, 60, allColfams, colfams);
colfams.add(new ArrayByteSequence(String.format("%06d", 61)));
runTest(cfi, 30000, 90, allColfams, colfams);
for (int i = 62; i < 100; i++) colfams.add(new ArrayByteSequence(String.format("%06d", i)));
runTest(cfi, 30000, 1230, allColfams, colfams);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class ColumnFilterTest method test2.
public void test2() 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("cf1"));
columns.add(newColumn("cf2", "cq1"));
SortedKeyValueIterator<Key, Value> cf = ColumnQualifierFilter.wrap(new SortedMapIterator(data), columns);
cf.seek(new Range(), Collections.emptySet(), false);
Assert.assertTrue(cf.hasTop());
Assert.assertEquals(newKey("r1", "cf1", "cq1"), cf.getTopKey());
cf.next();
Assert.assertTrue(cf.hasTop());
Assert.assertEquals(newKey("r1", "cf2", "cq1"), cf.getTopKey());
cf.next();
Assert.assertFalse(cf.hasTop());
}
Aggregations