Search in sources :

Example 1 with CountingIterator

use of org.apache.accumulo.core.iteratorsImpl.system.CountingIterator in project accumulo by apache.

the class ColumnFamilySkippingIteratorTest method test3.

@Test
public void test3() throws Exception {
    // construct test where ColumnFamilySkippingIterator might try to seek past the end of the user
    // supplied range
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    for (int r = 0; r < 3; r++) {
        for (int cf = 4; cf < 1000; cf++) {
            for (int cq = 0; cq < 1; cq++) {
                put(tm1, r, cf, cq, 6, r * cf * cq);
            }
        }
    }
    CountingIterator ci = new CountingIterator(new SortedMapIterator(tm1));
    ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(ci);
    HashSet<ByteSequence> colfams = new HashSet<>();
    colfams.add(new ArrayByteSequence(String.format("%06d", 4)));
    Range range = new Range(newKey(0, 4, 0, 6), true, newKey(0, 400, 0, 6), true);
    cfi.seek(range, colfams, true);
    assertTrue(cfi.hasTop());
    assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
    cfi.next();
    assertFalse(cfi.hasTop());
    colfams.add(new ArrayByteSequence(String.format("%06d", 500)));
    cfi.seek(range, colfams, true);
    assertTrue(cfi.hasTop());
    assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
    cfi.next();
    assertFalse(cfi.hasTop());
    range = new Range(newKey(0, 4, 0, 6), true, newKey(1, 400, 0, 6), true);
    cfi.seek(range, colfams, true);
    assertTrue(cfi.hasTop());
    assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
    cfi.next();
    assertTrue(cfi.hasTop());
    assertEquals(newKey(0, 500, 0, 6), cfi.getTopKey());
    cfi.next();
    assertTrue(cfi.hasTop());
    assertEquals(newKey(1, 4, 0, 6), cfi.getTopKey());
    cfi.next();
    assertFalse(cfi.hasTop());
// System.out.println(ci.getCount());
}
Also used : ColumnFamilySkippingIterator(org.apache.accumulo.core.iteratorsImpl.system.ColumnFamilySkippingIterator) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) CountingIterator(org.apache.accumulo.core.iteratorsImpl.system.CountingIterator) Value(org.apache.accumulo.core.data.Value) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with CountingIterator

use of org.apache.accumulo.core.iteratorsImpl.system.CountingIterator in project accumulo by apache.

the class FirstEntryInRowIteratorTest method process.

private static long process(TreeMap<Key, Value> sourceMap, TreeMap<Key, Value> resultMap, Range range, IteratorSetting iteratorSetting) throws IOException {
    SortedMapIterator source = new SortedMapIterator(sourceMap);
    CountingIterator counter = new CountingIterator(source);
    FirstEntryInRowIterator feiri = new FirstEntryInRowIterator();
    IteratorEnvironment env = new DefaultIteratorEnvironment();
    feiri.init(counter, iteratorSetting.getOptions(), env);
    feiri.seek(range, Set.of(), false);
    while (feiri.hasTop()) {
        resultMap.put(feiri.getTopKey(), feiri.getTopValue());
        feiri.next();
    }
    return counter.getCount();
}
Also used : CountingIterator(org.apache.accumulo.core.iteratorsImpl.system.CountingIterator) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator)

Aggregations

CountingIterator (org.apache.accumulo.core.iteratorsImpl.system.CountingIterator)2 SortedMapIterator (org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator)2 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)1 ByteSequence (org.apache.accumulo.core.data.ByteSequence)1 Key (org.apache.accumulo.core.data.Key)1 Range (org.apache.accumulo.core.data.Range)1 Value (org.apache.accumulo.core.data.Value)1 ColumnFamilySkippingIterator (org.apache.accumulo.core.iteratorsImpl.system.ColumnFamilySkippingIterator)1 Test (org.junit.jupiter.api.Test)1