use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class FilterTest method test3.
@Test
public void test3() throws IOException {
Value dv = new Value();
TreeMap<Key, Value> tm = new TreeMap<>();
HashSet<Column> hsc = new HashSet<>();
hsc.add(new Column("c".getBytes(), null, null));
Text colf1 = new Text("a");
Text colq1 = new Text("b");
Text colf2 = new Text("c");
Text colq2 = new Text("d");
Text colf;
Text colq;
for (int i = 0; i < 1000; i++) {
if (Math.abs(Math.ceil(i / 2.0) - i / 2.0) < .001) {
colf = colf1;
colq = colq1;
} else {
colf = colf2;
colq = colq2;
}
Key k = new Key(new Text(String.format("%03d", i)), colf, colq);
k.setTimestamp(157L);
tm.put(k, dv);
}
assertEquals(1000, tm.size());
SortedKeyValueIterator<Key, Value> a = ColumnQualifierFilter.wrap(new SortedMapIterator(tm), hsc);
a.seek(new Range(), EMPTY_COL_FAMS, false);
assertEquals(1000, size(a));
hsc = new HashSet<>();
hsc.add(new Column("a".getBytes(), "b".getBytes(), null));
a = ColumnQualifierFilter.wrap(new SortedMapIterator(tm), hsc);
a.seek(new Range(), EMPTY_COL_FAMS, false);
int size = size(a);
assertEquals(500, size);
hsc = new HashSet<>();
a = ColumnQualifierFilter.wrap(new SortedMapIterator(tm), hsc);
a.seek(new Range(), EMPTY_COL_FAMS, false);
size = size(a);
assertEquals(1000, size);
}
use of org.apache.accumulo.core.iteratorsImpl.system.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.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class FilterTest method testDeepCopy.
@Test
public void testDeepCopy() 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());
SimpleFilter filter = new SimpleFilter();
IteratorSetting is = new IteratorSetting(1, SimpleFilter.class);
Filter.setNegate(is, true);
filter.init(new SortedMapIterator(tm), is.getOptions(), null);
SortedKeyValueIterator<Key, Value> copy = filter.deepCopy(null);
filter.seek(new Range(), EMPTY_COL_FAMS, false);
int size = size(filter);
assertEquals(900, size);
copy.seek(new Range(), EMPTY_COL_FAMS, false);
size = size(copy);
assertEquals(900, size);
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class FilterTest method test2.
@Test
public void test2() 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);
k.setTimestamp(i);
tm.put(k, dv);
}
assertEquals(1000, tm.size());
SortedKeyValueIterator<Key, Value> a = new AgeOffFilter();
IteratorSetting is = new IteratorSetting(1, AgeOffFilter.class);
AgeOffFilter.setTTL(is, 101L);
AgeOffFilter.setCurrentTime(is, 1001L);
AgeOffFilter.setNegate(is, true);
final AgeOffFilter finalA = (AgeOffFilter) a;
assertTrue((finalA.validateOptions(is.getOptions())));
assertThrows(IllegalArgumentException.class, () -> finalA.validateOptions(EMPTY_OPTS));
a.init(new SortedMapIterator(tm), is.getOptions(), null);
a = a.deepCopy(null);
SortedKeyValueIterator<Key, Value> copy = a.deepCopy(null);
a.seek(new Range(), EMPTY_COL_FAMS, false);
assertEquals(900, size(a));
copy.seek(new Range(), EMPTY_COL_FAMS, false);
assertEquals(900, size(copy));
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class FilterTest method test2b.
/**
* Test for fix to ACCUMULO-1604: ColumnAgeOffFilter was throwing an error when using negate Test
* case for when "negate" is an actual column name
*/
@Test
public void test2b() throws IOException {
Text colf = new Text("negate");
Text colq = new Text("b");
Value dv = new Value();
TreeMap<Key, Value> tm = new TreeMap<>();
IteratorSetting is = new IteratorSetting(1, ColumnAgeOffFilter.class);
ColumnAgeOffFilter.addTTL(is, new IteratorSetting.Column("negate"), 901L);
long ts = System.currentTimeMillis();
for (long i = 0; i < 1000; i++) {
Key k = new Key(new Text(String.format("%03d", i)), colf, colq, ts - i);
tm.put(k, dv);
}
assertEquals(1000, tm.size());
ColumnAgeOffFilter a = new ColumnAgeOffFilter();
assertTrue(a.validateOptions(is.getOptions()));
a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
a.overrideCurrentTime(ts);
a.seek(new Range(), EMPTY_COL_FAMS, false);
assertEquals(902, size(a));
ColumnAgeOffFilter.addTTL(is, new IteratorSetting.Column("negate", "b"), 101L);
a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
a.overrideCurrentTime(ts);
a.seek(new Range(), EMPTY_COL_FAMS, false);
assertEquals(102, size(a));
ColumnAgeOffFilter.removeTTL(is, new IteratorSetting.Column("negate", "b"));
a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
a = (ColumnAgeOffFilter) a.deepCopy(null);
a.overrideCurrentTime(ts);
a.seek(new Range(), EMPTY_COL_FAMS, false);
assertEquals(902, size(a));
}
Aggregations