use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RegExFilterTest method testNullByteInKey.
@Test
public void testNullByteInKey() throws IOException {
TreeMap<Key, Value> tm = new TreeMap<>();
String s1 = "first", s2 = "second";
byte[] b1 = s1.getBytes(), b2 = s2.getBytes(), ball;
ball = new byte[b1.length + b2.length + 1];
System.arraycopy(b1, 0, ball, 0, b1.length);
ball[b1.length] = (byte) 0;
System.arraycopy(b2, 0, ball, b1.length + 1, b2.length);
Key key = new Key(ball, new byte[0], new byte[0], new byte[0], 90, false);
Value val = new Value(new byte[0]);
tm.put(key, val);
IteratorSetting is = new IteratorSetting(5, RegExFilter.class);
RegExFilter.setRegexs(is, s2, null, null, null, true, true);
RegExFilter filter = new RegExFilter();
filter.init(new SortedMapIterator(tm), is.getOptions(), null);
filter.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue("iterator couldn't find a match when it should have", filter.hasTop());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RowDeletingIteratorTest method test2.
public void test2() 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", 15, "v1");
put(tm1, "r1", "cf1", "cq4", 5, "v1");
put(tm1, "r1", "cf1", "cq5", 15, "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, "r1", "cf1", "cq3", 15, "v1");
rdi.next();
testAssertions(rdi, "r1", "cf1", "cq5", 15, "v1");
rdi.next();
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
rdi.seek(new Range(newKey("r1", "cf1", "cq1", 5), null), new ArrayList<>(), false);
testAssertions(rdi, "r1", "cf1", "cq3", 15, "v1");
rdi.next();
testAssertions(rdi, "r1", "cf1", "cq5", 15, "v1");
rdi.next();
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
rdi.seek(new Range(newKey("r1", "cf1", "cq4", 5), null), new ArrayList<>(), false);
testAssertions(rdi, "r1", "cf1", "cq5", 15, "v1");
rdi.next();
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
rdi.seek(new Range(newKey("r1", "cf1", "cq5", 20), null), new ArrayList<>(), false);
testAssertions(rdi, "r1", "cf1", "cq5", 15, "v1");
rdi.next();
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
rdi.seek(new Range(newKey("r1", "cf1", "cq9", 20), null), new ArrayList<>(), false);
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class ColumnFamilySkippingIteratorTest method test1.
public void test1() throws Exception {
TreeMap<Key, Value> tm1 = new TreeMap<>();
put(tm1, "r1", "cf1", "cq1", 5, "v1");
put(tm1, "r1", "cf1", "cq3", 5, "v2");
put(tm1, "r2", "cf1", "cq1", 5, "v3");
put(tm1, "r2", "cf2", "cq4", 5, "v4");
put(tm1, "r2", "cf2", "cq5", 5, "v5");
put(tm1, "r3", "cf3", "cq6", 5, "v6");
ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(new SortedMapIterator(tm1));
cfi.seek(new Range(), EMPTY_SET, true);
assertFalse(cfi.hasTop());
cfi.seek(new Range(), EMPTY_SET, false);
assertTrue(cfi.hasTop());
TreeMap<Key, Value> tm2 = new TreeMap<>();
while (cfi.hasTop()) {
tm2.put(cfi.getTopKey(), cfi.getTopValue());
cfi.next();
}
assertEquals(tm1, tm2);
HashSet<ByteSequence> colfams = new HashSet<>();
colfams.add(new ArrayByteSequence("cf2"));
cfi.seek(new Range(), colfams, true);
testAndCallnext(cfi, "r2", "cf2", "cq4", 5, "v4");
testAndCallnext(cfi, "r2", "cf2", "cq5", 5, "v5");
assertFalse(cfi.hasTop());
colfams.add(new ArrayByteSequence("cf3"));
colfams.add(new ArrayByteSequence("cf4"));
cfi.seek(new Range(), colfams, true);
testAndCallnext(cfi, "r2", "cf2", "cq4", 5, "v4");
testAndCallnext(cfi, "r2", "cf2", "cq5", 5, "v5");
testAndCallnext(cfi, "r3", "cf3", "cq6", 5, "v6");
assertFalse(cfi.hasTop());
cfi.seek(new Range(), colfams, false);
testAndCallnext(cfi, "r1", "cf1", "cq1", 5, "v1");
testAndCallnext(cfi, "r1", "cf1", "cq3", 5, "v2");
testAndCallnext(cfi, "r2", "cf1", "cq1", 5, "v3");
assertFalse(cfi.hasTop());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class ColumnFilterTest method test3.
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);
Assert.assertTrue(cf.hasTop());
Assert.assertEquals(newKey("r1", "cf2", "cq1"), cf.getTopKey());
cf.next();
Assert.assertFalse(cf.hasTop());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class DeletingIteratorTest method test4.
// test range inclusiveness
public void test4() throws IOException {
TreeMap<Key, Value> tm = new TreeMap<>();
newKeyValue(tm, "r000", 3, false, "v3");
newKeyValue(tm, "r000", 2, false, "v2");
newKeyValue(tm, "r000", 2, true, "");
newKeyValue(tm, "r000", 1, false, "v1");
DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), false);
it.seek(newRange("r000", 3), EMPTY_COL_FAMS, false);
assertTrue(it.hasTop());
assertEquals(newKey("r000", 3), it.getTopKey());
assertEquals("v3", it.getTopValue().toString());
it.next();
assertFalse(it.hasTop());
it.seek(newRange("r000", 3, false), EMPTY_COL_FAMS, false);
assertFalse(it.hasTop());
}
Aggregations