use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RowDeletingIteratorTest method test3.
public void test3() throws Exception {
TreeMap<Key, Value> tm1 = new TreeMap<>();
put(tm1, "r1", "", "", 10, RowDeletingIterator.DELETE_ROW_VALUE);
put(tm1, "r1", "", "cq1", 5, "v1");
put(tm1, "r1", "cf1", "cq1", 5, "v1");
put(tm1, "r2", "", "cq1", 5, "v1");
put(tm1, "r2", "cf1", "cq1", 5, "v1");
RowDeletingIterator rdi = new RowDeletingIterator();
rdi.init(new ColumnFamilySkippingIterator(new SortedMapIterator(tm1)), null, new TestIE(IteratorScope.scan, false));
HashSet<ByteSequence> cols = new HashSet<>();
cols.add(new ArrayByteSequence("cf1".getBytes()));
rdi.seek(new Range(), cols, true);
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
cols.clear();
cols.add(new ArrayByteSequence("".getBytes()));
rdi.seek(new Range(), cols, false);
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
cols.clear();
rdi.seek(new Range(), cols, false);
testAssertions(rdi, "r2", "", "cq1", 5, "v1");
rdi.next();
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RowDeletingIteratorTest method test1.
public void test1() throws Exception {
TreeMap<Key, Value> tm1 = new TreeMap<>();
put(tm1, "r1", "", "", 10, RowDeletingIterator.DELETE_ROW_VALUE);
put(tm1, "r1", "cf1", "cq1", 5, "v1");
put(tm1, "r1", "cf1", "cq3", 5, "v1");
put(tm1, "r2", "cf1", "cq1", 5, "v1");
RowDeletingIterator rdi = new RowDeletingIterator();
rdi.init(new SortedMapIterator(tm1), null, new TestIE(IteratorScope.scan, false));
rdi.seek(new Range(), new ArrayList<>(), false);
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
for (int i = 0; i < 5; i++) {
rdi.seek(new Range(newKey("r1", "cf1", "cq" + i, 5), null), new ArrayList<>(), false);
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
}
rdi.seek(new Range(newKey("r11", "cf1", "cq1", 5), null), new ArrayList<>(), false);
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
put(tm1, "r2", "", "", 10, RowDeletingIterator.DELETE_ROW_VALUE);
rdi.seek(new Range(), new ArrayList<>(), false);
assertFalse(rdi.hasTop());
for (int i = 0; i < 5; i++) {
rdi.seek(new Range(newKey("r1", "cf1", "cq" + i, 5), null), new ArrayList<>(), false);
assertFalse(rdi.hasTop());
}
put(tm1, "r0", "cf1", "cq1", 5, "v1");
rdi.seek(new Range(), new ArrayList<>(), false);
testAssertions(rdi, "r0", "cf1", "cq1", 5, "v1");
rdi.next();
assertFalse(rdi.hasTop());
}
use of org.apache.accumulo.core.iterators.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.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, RowEncodingIteratorImpl.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 RowEncodingIteratorTest method testEncodeSome.
@Test(expected = BufferOverflowException.class)
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());
iter.seek(range, new ArrayList<>(), false);
// BufferOverflowException should be thrown as RowEncodingIterator can't fit the whole row into its buffer.
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RowFilterTest method test1.
@Test
public void test1() throws Exception {
ColumnFamilySkippingIterator source = new ColumnFamilySkippingIterator(new SortedMapIterator(createKeyValues()));
RowFilter filter = new SummingRowFilter();
filter.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
filter.seek(new Range(), Collections.emptySet(), false);
assertEquals(new HashSet<>(Arrays.asList("2", "3")), getRows(filter));
ByteSequence cf = new ArrayByteSequence("cf2");
filter.seek(new Range(), ImmutableSet.of(cf), true);
assertEquals(new HashSet<>(Arrays.asList("1", "3", "0", "4")), getRows(filter));
filter.seek(new Range("0", "4"), Collections.emptySet(), false);
assertEquals(new HashSet<>(Arrays.asList("2", "3")), getRows(filter));
filter.seek(new Range("2"), Collections.emptySet(), false);
assertEquals(new HashSet<>(Arrays.asList("2")), getRows(filter));
filter.seek(new Range("4"), Collections.emptySet(), false);
assertEquals(new HashSet<String>(), getRows(filter));
filter.seek(new Range("4"), ImmutableSet.of(cf), true);
assertEquals(new HashSet<>(Arrays.asList("4")), getRows(filter));
}
Aggregations