Search in sources :

Example 6 with SortedMapIterator

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

the class FirstEntryInRowTest method test1.

@Test
public void test1() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq3", 5, "v2");
    put(tm1, "r2", "cf1", "cq1", 5, "v3");
    put(tm1, "r2", "cf2", "cq4", 5, "v4");
    put(tm1, "r2", "cf2", "cq5", 5, "v5");
    put(tm1, "r3", "cf3", "cq6", 5, "v6");
    FirstEntryInRowIterator fei = new FirstEntryInRowIterator();
    fei.init(new SortedMapIterator(tm1), EMPTY_MAP, null);
    fei.seek(new Range(), EMPTY_SET, false);
    testAndCallNext(fei, "r1", "cf1", "cq1", 5, "v1");
    testAndCallNext(fei, "r2", "cf1", "cq1", 5, "v3");
    testAndCallNext(fei, "r3", "cf3", "cq6", 5, "v6");
    assertFalse(fei.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 7 with SortedMapIterator

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

the class ColumnFamilySkippingIteratorTest method test1.

@Test
public void test1() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq3", 5, "v2");
    put(tm1, "r2", "cf1", "cq1", 5, "v3");
    put(tm1, "r2", "cf2", "cq4", 5, "v4");
    put(tm1, "r2", "cf2", "cq5", 5, "v5");
    put(tm1, "r3", "cf3", "cq6", 5, "v6");
    ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(new SortedMapIterator(tm1));
    cfi.seek(new Range(), EMPTY_SET, true);
    assertFalse(cfi.hasTop());
    cfi.seek(new Range(), EMPTY_SET, false);
    assertTrue(cfi.hasTop());
    TreeMap<Key, Value> tm2 = new TreeMap<>();
    while (cfi.hasTop()) {
        tm2.put(cfi.getTopKey(), cfi.getTopValue());
        cfi.next();
    }
    assertEquals(tm1, tm2);
    HashSet<ByteSequence> colfams = new HashSet<>();
    colfams.add(new ArrayByteSequence("cf2"));
    cfi.seek(new Range(), colfams, true);
    testAndCallnext(cfi, "r2", "cf2", "cq4", 5, "v4");
    testAndCallnext(cfi, "r2", "cf2", "cq5", 5, "v5");
    assertFalse(cfi.hasTop());
    colfams.add(new ArrayByteSequence("cf3"));
    colfams.add(new ArrayByteSequence("cf4"));
    cfi.seek(new Range(), colfams, true);
    testAndCallnext(cfi, "r2", "cf2", "cq4", 5, "v4");
    testAndCallnext(cfi, "r2", "cf2", "cq5", 5, "v5");
    testAndCallnext(cfi, "r3", "cf3", "cq6", 5, "v6");
    assertFalse(cfi.hasTop());
    cfi.seek(new Range(), colfams, false);
    testAndCallnext(cfi, "r1", "cf1", "cq1", 5, "v1");
    testAndCallnext(cfi, "r1", "cf1", "cq3", 5, "v2");
    testAndCallnext(cfi, "r2", "cf1", "cq1", 5, "v3");
    assertFalse(cfi.hasTop());
}
Also used : ColumnFamilySkippingIterator(org.apache.accumulo.core.iteratorsImpl.system.ColumnFamilySkippingIterator) Value(org.apache.accumulo.core.data.Value) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) 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 8 with SortedMapIterator

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

the class DeletingIteratorTest method test1.

@Test
public void test1() {
    Text colf = new Text("a");
    Text colq = new Text("b");
    Value dvOld = new Value("old");
    Value dvDel = new Value("old");
    Value dvNew = new Value("new");
    TreeMap<Key, Value> tm = new TreeMap<>();
    Key k;
    for (int i = 0; i < 2; i++) {
        for (long j = 0; j < 5; j++) {
            k = new Key(new Text(String.format("%03d", i)), colf, colq, j);
            tm.put(k, dvOld);
        }
    }
    k = new Key(new Text(String.format("%03d", 0)), colf, colq, 5);
    k.setDeleted(true);
    tm.put(k, dvDel);
    for (int i = 0; i < 2; i++) {
        for (long j = 6; j < 11; j++) {
            k = new Key(new Text(String.format("%03d", i)), colf, colq, j);
            tm.put(k, dvNew);
        }
    }
    assertEquals(21, tm.size(), "Initial size was " + tm.size());
    Text checkRow = new Text("000");
    try {
        SortedKeyValueIterator<Key, Value> it = DeletingIterator.wrap(new SortedMapIterator(tm), false, Behavior.PROCESS);
        it.seek(new Range(), EMPTY_COL_FAMS, false);
        TreeMap<Key, Value> tmOut = new TreeMap<>();
        while (it.hasTop()) {
            tmOut.put(it.getTopKey(), it.getTopValue());
            it.next();
        }
        assertEquals(15, tmOut.size(), "size after no propagation was " + tmOut.size());
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            if (e.getKey().getRow().equals(checkRow)) {
                byte[] b = e.getValue().get();
                assertEquals('n', b[0]);
                assertEquals('e', b[1]);
                assertEquals('w', b[2]);
            }
        }
    } catch (IOException e) {
        fail();
    }
    try {
        SortedKeyValueIterator<Key, Value> it = DeletingIterator.wrap(new SortedMapIterator(tm), true, Behavior.PROCESS);
        it.seek(new Range(), EMPTY_COL_FAMS, false);
        TreeMap<Key, Value> tmOut = new TreeMap<>();
        while (it.hasTop()) {
            tmOut.put(it.getTopKey(), it.getTopValue());
            it.next();
        }
        assertEquals(16, tmOut.size(), "size after propagation was " + tmOut.size());
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            if (e.getKey().getRow().equals(checkRow)) {
                byte[] b = e.getValue().get();
                if (e.getKey().isDeleted()) {
                    assertEquals('o', b[0]);
                    assertEquals('l', b[1]);
                    assertEquals('d', b[2]);
                } else {
                    assertEquals('n', b[0]);
                    assertEquals('e', b[1]);
                    assertEquals('w', b[2]);
                }
            }
        }
    } catch (IOException e) {
        fail();
    }
}
Also used : Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 9 with SortedMapIterator

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

the class DeletingIteratorTest method test4.

// test range inclusiveness
@Test
public void test4() throws IOException {
    TreeMap<Key, Value> tm = new TreeMap<>();
    newKeyValue(tm, "r000", 3, false, "v3");
    newKeyValue(tm, "r000", 2, false, "v2");
    newKeyValue(tm, "r000", 2, true, "");
    newKeyValue(tm, "r000", 1, false, "v1");
    SortedKeyValueIterator<Key, Value> it = DeletingIterator.wrap(new SortedMapIterator(tm), false, Behavior.PROCESS);
    it.seek(newRange("r000", 3), EMPTY_COL_FAMS, false);
    assertTrue(it.hasTop());
    assertEquals(newKey("r000", 3), it.getTopKey());
    assertEquals("v3", it.getTopValue().toString());
    it.next();
    assertFalse(it.hasTop());
    it.seek(newRange("r000", 3, false), EMPTY_COL_FAMS, false);
    assertFalse(it.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 10 with SortedMapIterator

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

the class DeletingIteratorTest method testFail.

@Test
public void testFail() throws IOException {
    TreeMap<Key, Value> tm = new TreeMap<>();
    newKeyValue(tm, "r000", 3, false, "v3");
    newKeyValue(tm, "r000", 2, false, "v2");
    newKeyValue(tm, "r000", 2, true, "");
    newKeyValue(tm, "r000", 1, false, "v1");
    SortedKeyValueIterator<Key, Value> it = DeletingIterator.wrap(new SortedMapIterator(tm), false, Behavior.FAIL);
    it.seek(new Range(), EMPTY_COL_FAMS, false);
    // first entry should pass
    it.getTopKey();
    it.next();
    // second entry should fail due to delete
    assertThrows(IllegalStateException.class, it::getTopKey);
    it.next();
    // third entry should pass
    it.getTopKey();
    it.next();
    // fourth entry should pass
    it.getTopKey();
    it.next();
}
Also used : Value(org.apache.accumulo.core.data.Value) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Aggregations

SortedMapIterator (org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator)109 Test (org.junit.jupiter.api.Test)97 Range (org.apache.accumulo.core.data.Range)93 Key (org.apache.accumulo.core.data.Key)89 Value (org.apache.accumulo.core.data.Value)89 TreeMap (java.util.TreeMap)82 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)38 Text (org.apache.hadoop.io.Text)29 PartialKey (org.apache.accumulo.core.data.PartialKey)16 Combiner (org.apache.accumulo.core.iterators.Combiner)12 LongCombiner (org.apache.accumulo.core.iterators.LongCombiner)12 TypedValueCombiner (org.apache.accumulo.core.iterators.TypedValueCombiner)12 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)9 DefaultIteratorEnvironment (org.apache.accumulo.core.iterators.DefaultIteratorEnvironment)8 ColumnFamilySkippingIterator (org.apache.accumulo.core.iteratorsImpl.system.ColumnFamilySkippingIterator)8 MultiIterator (org.apache.accumulo.core.iteratorsImpl.system.MultiIterator)8 ByteSequence (org.apache.accumulo.core.data.ByteSequence)7 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)7 SourceSwitchingIterator (org.apache.accumulo.core.iteratorsImpl.system.SourceSwitchingIterator)7