use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class CombinerTest method test2.
@Test
public void test2() 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, 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, VarLenEncoder.class);
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();
assertFalse(ai.hasTop());
// try seeking to the beginning of a key that aggregates
ai.seek(newRow(1, 1, 1, 3), 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();
assertFalse(ai.hasTop());
// try seeking the middle of a key the aggregates
ai.seek(newRow(1, 1, 1, 2), EMPTY_COL_FAMS, false);
assertFalse(ai.hasTop());
// try seeking to the end of a key the aggregates
ai.seek(newRow(1, 1, 1, 1), EMPTY_COL_FAMS, false);
assertFalse(ai.hasTop());
// try seeking before a key the 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();
assertFalse(ai.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.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.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class CombinerTest method sumAllColumns.
@Test
public void sumAllColumns() throws IOException {
TreeMap<Key, Value> tm = new TreeMap<>();
tm.put(new Key("r", "count", "a", 1), new Value("1"));
tm.put(new Key("r", "count", "a", 2), new Value("1"));
tm.put(new Key("r", "count", "b", 3), new Value("1"));
tm.put(new Key("r", "count", "b", 4), new Value("1"));
tm.put(new Key("r", "count", "b", 5), new Value("1"));
tm.put(new Key("r", "count", "c", 6), new Value("1"));
SortedMapIterator smi = new SortedMapIterator(tm);
Combiner iter = new SummingCombiner();
IteratorSetting s = new IteratorSetting(10, "s", SummingCombiner.class);
SummingCombiner.setColumns(s, Collections.singletonList(new IteratorSetting.Column("count")));
SummingCombiner.setEncodingType(s, LongCombiner.StringEncoder.class);
iter.init(smi, s.getOptions(), SCAN_IE);
Combiner iter2 = new SummingCombiner();
IteratorSetting s2 = new IteratorSetting(10, "s2", SummingCombiner.class);
SummingCombiner.setColumns(s2, Collections.singletonList(new IteratorSetting.Column("count", "a")));
SummingCombiner.setEncodingType(s2, LongCombiner.StringEncoder.class);
iter2.init(iter, s.getOptions(), SCAN_IE);
iter2.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(iter2.hasTop());
assertEquals("2", iter2.getTopValue().toString());
iter2.next();
assertTrue(iter2.hasTop());
assertEquals("3", iter2.getTopValue().toString());
iter2.next();
assertTrue(iter2.hasTop());
assertEquals("1", iter2.getTopValue().toString());
iter2.next();
assertFalse(iter2.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class CombinerTest method sumArray.
public static void sumArray(Class<? extends Encoder<List<Long>>> encoderClass, SummingArrayCombiner.Type type) throws IOException, ReflectiveOperationException {
Encoder<List<Long>> encoder = encoderClass.getDeclaredConstructor().newInstance();
TreeMap<Key, Value> tm1 = new TreeMap<>();
// keys that aggregate
newKeyValue(tm1, 1, 1, 1, 1, false, nal(1L, 2L), encoder);
newKeyValue(tm1, 1, 1, 1, 2, false, nal(3L, 4L, 5L), encoder);
newKeyValue(tm1, 1, 1, 1, 3, false, nal(), encoder);
Combiner ai = new SummingArrayCombiner();
IteratorSetting is = new IteratorSetting(1, SummingArrayCombiner.class);
SummingArrayCombiner.setEncodingType(is, type);
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
SortedMapIterator sortedMapIterator = new SortedMapIterator(tm1);
ai.init(sortedMapIterator, is.getOptions(), SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertBytesEqual(encoder.encode(nal(4L, 6L, 5L)), ai.getTopValue().get());
ai.next();
assertFalse(ai.hasTop());
is.clearOptions();
SummingArrayCombiner.setEncodingType(is, encoderClass);
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
ai.init(sortedMapIterator, is.getOptions(), SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertBytesEqual(encoder.encode(nal(4L, 6L, 5L)), ai.getTopValue().get());
ai.next();
assertFalse(ai.hasTop());
is.clearOptions();
SummingArrayCombiner.setEncodingType(is, encoderClass.getName());
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
ai.init(sortedMapIterator, is.getOptions(), SCAN_IE);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
assertTrue(ai.hasTop());
assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
assertBytesEqual(encoder.encode(nal(4L, 6L, 5L)), ai.getTopValue().get());
ai.next();
assertFalse(ai.hasTop());
is.clearOptions();
SummingArrayCombiner.setEncodingType(is, SummingCombiner.VAR_LEN_ENCODER.getClass().getName());
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
final var isOptions = is.getOptions();
assertThrows(IllegalArgumentException.class, () -> ai.init(sortedMapIterator, isOptions, SCAN_IE));
is.clearOptions();
SummingArrayCombiner.setEncodingType(is, BadEncoder.class.getName());
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
final var isOptions1 = is.getOptions();
assertThrows(IllegalArgumentException.class, () -> ai.init(sortedMapIterator, isOptions1, SCAN_IE));
}
use of org.apache.accumulo.core.iteratorsImpl.system.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));
}
Aggregations