use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class FilterTest method testDeletes.
@Test
public void testDeletes() throws IOException {
Text colf = new Text("a");
Text colq = new Text("b");
Value dv = new Value();
TreeMap<Key, Value> tm = new TreeMap<>();
Key k = new Key(new Text("0"), colf, colq);
tm.put(k, dv);
k = new Key(new Text("1"), colf, colq, 10);
k.setDeleted(true);
tm.put(k, dv);
k = new Key(new Text("1"), colf, colq, 5);
tm.put(k, dv);
k = new Key(new Text("10"), colf, colq);
tm.put(k, dv);
assertEquals(4, tm.size());
Filter filter = new SimpleFilter();
filter.init(new SortedMapIterator(tm), EMPTY_OPTS, null);
filter.seek(new Range(), EMPTY_COL_FAMS, false);
int size = size(filter);
assertEquals(3, size);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class FilterTest method test1neg.
@Test
public void test1neg() throws IOException {
Text colf = new Text("a");
Text colq = new Text("b");
Value dv = new Value();
TreeMap<Key, Value> tm = new TreeMap<>();
for (int i = 0; i < 1000; i++) {
Key k = new Key(new Text(String.format("%03d", i)), colf, colq);
tm.put(k, dv);
}
assertEquals(1000, tm.size());
Filter filter = new SimpleFilter();
IteratorSetting is = new IteratorSetting(1, SimpleFilter.class);
Filter.setNegate(is, true);
filter.init(new SortedMapIterator(tm), is.getOptions(), null);
filter.seek(new Range(), EMPTY_COL_FAMS, false);
int size = size(filter);
assertEquals(900, size);
filter.init(new SortedMapIterator(tm), is.getOptions(), null);
Key k = new Key(new Text("500"));
filter.seek(new Range(k, null), EMPTY_COL_FAMS, false);
size = size(filter);
assertEquals(450, size);
filter.init(new SortedMapIterator(tm), EMPTY_OPTS, null);
Filter filter2 = new SimpleFilter2();
filter2.init(filter, is.getOptions(), null);
filter2.seek(new Range(), EMPTY_COL_FAMS, false);
size = size(filter2);
assertEquals(100, size);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class GrepIteratorTest method test.
@Test
public void test() throws IOException {
GrepIterator gi = new GrepIterator();
IteratorSetting is = new IteratorSetting(1, GrepIterator.class);
GrepIterator.setTerm(is, "ab");
gi.init(new SortedMapIterator(input), is.getOptions(), null);
gi.seek(new Range(), EMPTY_COL_FAMS, false);
checkEntries(gi, output);
GrepIterator.setTerm(is, "cde");
gi.init(new SortedMapIterator(input), is.getOptions(), null);
gi.deepCopy(null);
gi.seek(new Range(), EMPTY_COL_FAMS, false);
checkEntries(gi, output);
GrepIterator.setTerm(is, "def");
gi.init(new SortedMapIterator(input), is.getOptions(), null);
gi.seek(new Range(), EMPTY_COL_FAMS, false);
checkEntries(gi, output);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class LargeRowFilterTest method setupIterator.
private LargeRowFilter setupIterator(TreeMap<Key, Value> testData, int maxColumns, IteratorScope scope) throws IOException {
SortedMapIterator smi = new SortedMapIterator(testData);
LargeRowFilter lrfi = new LargeRowFilter();
IteratorSetting is = new IteratorSetting(1, LargeRowFilter.class);
LargeRowFilter.setMaxColumns(is, maxColumns);
lrfi.init(new ColumnFamilySkippingIterator(smi), is.getOptions(), new RowDeletingIteratorTest.TestIE(scope, false));
return lrfi;
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RegExFilterTest method test1.
@Test
public void test1() throws IOException {
TreeMap<Key, Value> tm = new TreeMap<>();
Key k1 = newKeyValue(tm, "boo1", "yup", "20080201", "dog");
Key k2 = newKeyValue(tm, "boo1", "yap", "20080202", "cat");
Key k3 = newKeyValue(tm, "boo2", "yip", "20080203", "hamster");
RegExFilter rei = new RegExFilter();
rei.describeOptions();
IteratorSetting is = new IteratorSetting(1, RegExFilter.class);
RegExFilter.setRegexs(is, ".*2", null, null, null, false);
assertTrue(rei.validateOptions(is.getOptions()));
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k3));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
// Test substring regex
is.clearOptions();
// Should only match hamster
RegExFilter.setRegexs(is, null, null, null, "amst", false, true);
rei.validateOptions(is.getOptions());
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k3));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, null, "ya.*", null, null, false);
assertTrue(rei.validateOptions(is.getOptions()));
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k2));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, null, null, ".*01", null, false);
assertTrue(rei.validateOptions(is.getOptions()));
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k1));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, null, null, null, ".*at", false);
assertTrue(rei.validateOptions(is.getOptions()));
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k2));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, null, null, null, ".*ap", false);
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, null, "ya.*", null, ".*at", false);
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k2));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, null, "ya.*", null, ".*ap", false);
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, "boo1", null, null, null, false);
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k2));
rei.next();
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k1));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k2));
rei.next();
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k1));
rei.next();
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k3));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, "hamster", null, "hamster", "hamster", true);
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k3));
rei.next();
assertFalse(rei.hasTop());
// -----------------------------------------------------
is.clearOptions();
RegExFilter.setRegexs(is, null, "ya.*", "hamster", null, true);
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
assertTrue(rei.getTopKey().equals(k2));
rei.next();
assertFalse(rei.hasTop());
is.clearOptions();
RegExFilter.setRegexs(is, null, "ya.*", "hamster", null, true);
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
rei.deepCopy(new DefaultIteratorEnvironment());
// -----------------------------------------------------
String multiByteText = new String("\u6d67" + "\u6F68" + "\u7067");
String multiByteRegex = new String(".*" + "\u6F68" + ".*");
Key k4 = new Key("boo4".getBytes(), "hoo".getBytes(), "20080203".getBytes(), "".getBytes(), 1l);
Value inVal = new Value(multiByteText.getBytes(UTF_8));
tm.put(k4, inVal);
is.clearOptions();
RegExFilter.setRegexs(is, null, null, null, multiByteRegex, true);
rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
rei.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(rei.hasTop());
Value outValue = rei.getTopValue();
String outVal = new String(outValue.get(), UTF_8);
assertTrue(outVal.equals(multiByteText));
}
Aggregations