use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class CombinerTest method test3.
@Test
public void test3() throws IOException {
Encoder<Long> encoder = LongCombiner.FIXED_LEN_ENCODER;
TreeMap<Key, Value> tm1 = new TreeMap<>();
// keys that aggregate
newKeyValue(tm1, 1, 1, 1, 1, false, 2l, encoder);
newKeyValue(tm1, 1, 1, 1, 2, false, 3l, encoder);
newKeyValue(tm1, 1, 1, 1, 3, false, 4l, encoder);
// keys that do not aggregate
newKeyValue(tm1, 2, 2, 1, 1, false, 2l, encoder);
newKeyValue(tm1, 2, 2, 1, 2, false, 3l, encoder);
Combiner ai = new SummingCombiner();
IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
LongCombiner.setEncodingType(is, FixedLenEncoder.class.getName());
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(2, 2, 1, 1), ai.getTopKey());
assertEquals("2", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
// seek after key that aggregates
ai.seek(newRow(1, 1, 1, 2), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
// seek before key that aggregates
ai.seek(newRow(1, 1, 1, 4), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class CombinerTest method maxMinTest.
@Test
public void maxMinTest() throws IOException {
Encoder<Long> encoder = LongCombiner.VAR_LEN_ENCODER;
TreeMap<Key, Value> tm1 = new TreeMap<>();
// keys that aggregate
newKeyValue(tm1, 1, 1, 1, 1, false, 4l, encoder);
newKeyValue(tm1, 1, 1, 1, 2, false, 3l, encoder);
newKeyValue(tm1, 1, 1, 1, 3, false, 2l, encoder);
Combiner ai = new MaxCombiner();
IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
LongCombiner.setEncodingType(is, SummingCombiner.Type.VARLEN);
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals("4", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
ai = new MinCombiner();
ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals("2", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class CombinerTest method test1.
@Test
public void test1() throws IOException {
Encoder<Long> encoder = LongCombiner.VAR_LEN_ENCODER;
TreeMap<Key, Value> tm1 = new TreeMap<>();
// keys that do not aggregate
newKeyValue(tm1, 1, 1, 1, 1, false, 2l, encoder);
newKeyValue(tm1, 1, 1, 1, 2, false, 3l, encoder);
newKeyValue(tm1, 1, 1, 1, 3, false, 4l, encoder);
Combiner ai = new SummingCombiner();
IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
LongCombiner.setEncodingType(is, SummingCombiner.Type.VARLEN);
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("2")));
ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertEquals("4", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 2), ai.getTopKey());
assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 1), ai.getTopKey());
assertEquals("2", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
// try seeking
ai.seek(newRow(1, 1, 1, 2), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 2), ai.getTopKey());
assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 1), ai.getTopKey());
assertEquals("2", encoder.decode(ai.getTopValue().get()).toString());
ai.next();
assertFalse(ai.hasTop());
// seek after everything
ai.seek(newRow(1, 1, 1, 0), EMPTY_COL_FAMS, false);
assertFalse(ai.hasTop());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class FilterTest method test2aNegate.
/**
* Test for fix to ACCUMULO-1604: ColumnAgeOffFilter was throwing an error when using negate
*/
@Test
public void test2aNegate() throws IOException {
Text colf = new Text("a");
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("a"), 901l);
ColumnAgeOffFilter.setNegate(is, true);
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(98, size(a));
ColumnAgeOffFilter.addTTL(is, new IteratorSetting.Column("a", "b"), 101l);
a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
a.overrideCurrentTime(ts);
a.seek(new Range(), EMPTY_COL_FAMS, false);
assertEquals(898, size(a));
ColumnAgeOffFilter.removeTTL(is, new IteratorSetting.Column("a", "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(98, size(a));
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RowDeletingIteratorTest method test4.
public void test4() 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, "r2", "cf1", "cq1", 5, "v1");
RowDeletingIterator rdi = new RowDeletingIterator();
rdi.init(new SortedMapIterator(tm1), null, new TestIE(IteratorScope.minc, false));
rdi.seek(new Range(), new ArrayList<>(), false);
testAssertions(rdi, "r1", "", "", 10, RowDeletingIterator.DELETE_ROW_VALUE.toString());
rdi.next();
testAssertions(rdi, "r1", "cf1", "cq3", 15, "v1");
rdi.next();
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
rdi.seek(new Range(newKey("r1", "cf1", "cq3", 20), null), new ArrayList<>(), false);
testAssertions(rdi, "r1", "cf1", "cq3", 15, "v1");
rdi.next();
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
rdi.seek(new Range(newKey("r1", "", "", 42), null), new ArrayList<>(), false);
testAssertions(rdi, "r1", "", "", 10, RowDeletingIterator.DELETE_ROW_VALUE.toString());
rdi.next();
testAssertions(rdi, "r1", "cf1", "cq3", 15, "v1");
rdi.next();
testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
}
Aggregations