Search in sources :

Example 26 with SortedMapIterator

use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.

the class DeletingIteratorTest method test1.

public void test1() {
    Text colf = new Text("a");
    Text colq = new Text("b");
    Value dvOld = new Value("old".getBytes());
    Value dvDel = new Value("old".getBytes());
    Value dvNew = new Value("new".getBytes());
    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);
        }
    }
    assertTrue("Initial size was " + tm.size(), tm.size() == 21);
    Text checkRow = new Text("000");
    try {
        DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), false);
        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();
        }
        assertTrue("size after no propagation was " + tmOut.size(), tmOut.size() == 15);
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            if (e.getKey().getRow().equals(checkRow)) {
                byte[] b = e.getValue().get();
                assertTrue(b[0] == 'n');
                assertTrue(b[1] == 'e');
                assertTrue(b[2] == 'w');
            }
        }
    } catch (IOException e) {
        assertFalse(true);
    }
    try {
        DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), true);
        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();
        }
        assertTrue("size after propagation was " + tmOut.size(), tmOut.size() == 16);
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            if (e.getKey().getRow().equals(checkRow)) {
                byte[] b = e.getValue().get();
                if (e.getKey().isDeleted()) {
                    assertTrue(b[0] == 'o');
                    assertTrue(b[1] == 'l');
                    assertTrue(b[2] == 'd');
                } else {
                    assertTrue(b[0] == 'n');
                    assertTrue(b[1] == 'e');
                    assertTrue(b[2] == 'w');
                }
            }
        }
    } catch (IOException e) {
        assertFalse(true);
    }
}
Also used : Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 27 with SortedMapIterator

use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.

the class DeletingIteratorTest method test2.

// seek test
public void test2() throws IOException {
    TreeMap<Key, Value> tm = new TreeMap<>();
    newKeyValue(tm, "r000", 4, false, "v4");
    newKeyValue(tm, "r000", 3, false, "v3");
    newKeyValue(tm, "r000", 2, true, "v2");
    newKeyValue(tm, "r000", 1, false, "v1");
    DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), false);
    // SEEK two keys before delete
    it.seek(newRange("r000", 4), EMPTY_COL_FAMS, false);
    assertTrue(it.hasTop());
    assertEquals(newKey("r000", 4), it.getTopKey());
    assertEquals("v4", it.getTopValue().toString());
    it.next();
    assertTrue(it.hasTop());
    assertEquals(newKey("r000", 3), it.getTopKey());
    assertEquals("v3", it.getTopValue().toString());
    it.next();
    assertFalse(it.hasTop());
    // SEEK passed delete
    it.seek(newRange("r000", 1), EMPTY_COL_FAMS, false);
    assertFalse(it.hasTop());
    // SEEK to delete
    it.seek(newRange("r000", 2), EMPTY_COL_FAMS, false);
    assertFalse(it.hasTop());
    // SEEK right before delete
    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());
}
Also used : Value(org.apache.accumulo.core.data.Value) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Key(org.apache.accumulo.core.data.Key)

Example 28 with SortedMapIterator

use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.

the class MultiIteratorTest method test4.

public void test4() throws IOException {
    // TEST empty input
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    List<SortedKeyValueIterator<Key, Value>> skvil = new ArrayList<>(1);
    skvil.add(new SortedMapIterator(tm1));
    MultiIterator mi = new MultiIterator(skvil, true);
    assertFalse(mi.hasTop());
    mi.seek(newRange(0, 6), EMPTY_COL_FAMS, false);
    assertFalse(mi.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) ArrayList(java.util.ArrayList) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Key(org.apache.accumulo.core.data.Key)

Example 29 with SortedMapIterator

use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.

the class MultiIteratorTest method verify.

void verify(int start, int end, Key seekKey, Text endRow, Text prevEndRow, boolean init, boolean incrRow, List<TreeMap<Key, Value>> maps) throws IOException {
    List<SortedKeyValueIterator<Key, Value>> iters = new ArrayList<>(maps.size());
    for (TreeMap<Key, Value> map : maps) {
        iters.add(new SortedMapIterator(map));
    }
    MultiIterator mi;
    if (endRow == null && prevEndRow == null)
        mi = new MultiIterator(iters, init);
    else {
        Range range = new Range(prevEndRow, false, endRow, true);
        if (init)
            for (SortedKeyValueIterator<Key, Value> iter : iters) iter.seek(range, LocalityGroupUtil.EMPTY_CF_SET, false);
        mi = new MultiIterator(iters, range);
        if (init)
            mi.seek(range, LocalityGroupUtil.EMPTY_CF_SET, false);
    }
    if (seekKey != null)
        mi.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
    else
        mi.seek(new Range(), EMPTY_COL_FAMS, false);
    int i = start;
    while (mi.hasTop()) {
        if (incrRow)
            assertEquals(newKey(i, 0), mi.getTopKey());
        else
            assertEquals(newKey(0, i), mi.getTopKey());
        assertEquals("v" + i, mi.getTopValue().toString());
        mi.next();
        if (incrRow)
            i++;
        else
            i--;
    }
    assertEquals("start=" + start + " end=" + end + " seekKey=" + seekKey + " endRow=" + endRow + " prevEndRow=" + prevEndRow + " init=" + init + " incrRow=" + incrRow + " maps=" + maps, end, i);
}
Also used : ArrayList(java.util.ArrayList) Value(org.apache.accumulo.core.data.Value) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Example 30 with SortedMapIterator

use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.

the class MultiIteratorTest method test6.

public void test6() throws IOException {
    // TEst setting an endKey
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    newKeyValue(tm1, 3, 0, false, "1");
    newKeyValue(tm1, 4, 0, false, "2");
    newKeyValue(tm1, 6, 0, false, "3");
    List<SortedKeyValueIterator<Key, Value>> skvil = new ArrayList<>(1);
    skvil.add(new SortedMapIterator(tm1));
    MultiIterator mi = new MultiIterator(skvil, true);
    mi.seek(new Range(null, true, newKey(5, 9), false), EMPTY_COL_FAMS, false);
    assertTrue(mi.hasTop());
    assertTrue(mi.getTopKey().equals(newKey(3, 0)));
    assertTrue(mi.getTopValue().toString().equals("1"));
    mi.next();
    assertTrue(mi.hasTop());
    assertTrue(mi.getTopKey().equals(newKey(4, 0)));
    assertTrue(mi.getTopValue().toString().equals("2"));
    mi.next();
    assertFalse(mi.hasTop());
    mi.seek(new Range(newKey(4, 10), true, newKey(5, 9), false), EMPTY_COL_FAMS, false);
    assertTrue(mi.hasTop());
    assertTrue(mi.getTopKey().equals(newKey(4, 0)));
    assertTrue(mi.getTopValue().toString().equals("2"));
    mi.next();
    assertFalse(mi.hasTop());
    mi.seek(new Range(newKey(4, 10), true, newKey(6, 0), false), EMPTY_COL_FAMS, false);
    assertTrue(mi.hasTop());
    assertTrue(mi.getTopKey().equals(newKey(4, 0)));
    assertTrue(mi.getTopValue().toString().equals("2"));
    mi.next();
    assertFalse(mi.hasTop());
    mi.seek(new Range(newKey(4, 10), true, newKey(6, 0), true), EMPTY_COL_FAMS, false);
    assertTrue(mi.hasTop());
    assertTrue(mi.getTopKey().equals(newKey(4, 0)));
    assertTrue(mi.getTopValue().toString().equals("2"));
    mi.next();
    assertTrue(mi.hasTop());
    assertTrue(mi.getTopKey().equals(newKey(6, 0)));
    assertTrue(mi.getTopValue().toString().equals("3"));
    mi.next();
    assertFalse(mi.hasTop());
    mi.seek(new Range(newKey(4, 0), true, newKey(6, 0), false), EMPTY_COL_FAMS, false);
    assertTrue(mi.hasTop());
    assertTrue(mi.getTopKey().equals(newKey(4, 0)));
    assertTrue(mi.getTopValue().toString().equals("2"));
    mi.next();
    assertFalse(mi.hasTop());
    mi.seek(new Range(newKey(4, 0), false, newKey(6, 0), false), EMPTY_COL_FAMS, false);
    assertFalse(mi.hasTop());
    mi.seek(new Range(newKey(4, 0), false, newKey(6, 0), true), EMPTY_COL_FAMS, false);
    assertTrue(mi.hasTop());
    assertTrue(mi.getTopKey().equals(newKey(6, 0)));
    assertTrue(mi.getTopValue().toString().equals("3"));
    mi.next();
    assertFalse(mi.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) ArrayList(java.util.ArrayList) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Aggregations

SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)100 Range (org.apache.accumulo.core.data.Range)86 Key (org.apache.accumulo.core.data.Key)82 Value (org.apache.accumulo.core.data.Value)82 TreeMap (java.util.TreeMap)74 Test (org.junit.Test)61 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)10 HashSet (java.util.HashSet)9 DefaultIteratorEnvironment (org.apache.accumulo.core.iterators.DefaultIteratorEnvironment)8 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)7 IOException (java.io.IOException)6 ByteSequence (org.apache.accumulo.core.data.ByteSequence)6 HashMap (java.util.HashMap)5 ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)5