Search in sources :

Example 46 with SortedMapIterator

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

the class VersioningIteratorTest method test6.

@Test
public void test6() throws IOException {
    Text colf = new Text("a");
    Text colq = new Text("b");
    TreeMap<Key, Value> tm = new TreeMap<>();
    createTestData(tm, colf, colq);
    VersioningIterator it = new VersioningIterator();
    IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
    VersioningIterator.setMaxVersions(is, 3);
    it.init(new SortedMapIterator(tm), is.getOptions(), null);
    VersioningIterator it2 = it.deepCopy(null);
    Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 19);
    it.seek(new Range(seekKey, false, null, true), EMPTY_COL_FAMS, false);
    it2.seek(new Range(seekKey, false, null, true), EMPTY_COL_FAMS, false);
    assertTrue(it.hasTop());
    assertTrue(it.getTopKey().getTimestamp() == 18);
    assertTrue(it2.hasTop());
    assertTrue(it2.getTopKey().getTimestamp() == 18);
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) 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) PartialKey(org.apache.accumulo.core.data.PartialKey) Test(org.junit.Test)

Example 47 with SortedMapIterator

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

the class VersioningIteratorTest method test3.

@Test
public void test3() {
    Text colf = new Text("a");
    Text colq = new Text("b");
    TreeMap<Key, Value> tm = new TreeMap<>();
    createTestData(tm, colf, colq);
    try {
        VersioningIterator it = new VersioningIterator();
        IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
        VersioningIterator.setMaxVersions(is, 3);
        it.init(new SortedMapIterator(tm), is.getOptions(), null);
        // after doing this seek, should get zero keys for row 1
        Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 15);
        it.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
        TreeMap<Key, Value> tmOut = iteratorOverTestData(it);
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            assertTrue(e.getValue().get().length == 8);
            assertTrue(16 < encoder.decode(e.getValue().get()));
        }
        assertTrue("size after seeking past versions was " + tmOut.size(), tmOut.size() == 0);
        // after doing this seek, should get zero keys for row 0 and 3 keys for row 1
        seekKey = new Key(new Text(String.format("%03d", 0)), colf, colq, 15);
        it.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
        tmOut = iteratorOverTestData(it);
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            assertTrue(e.getValue().get().length == 8);
            assertTrue(16 < encoder.decode(e.getValue().get()));
        }
        assertTrue("size after seeking past versions was " + tmOut.size(), tmOut.size() == 3);
    } catch (IOException e) {
        assertFalse(true);
    } catch (Exception e) {
        log.error("{}", e.getMessage(), e);
        assertFalse(true);
    }
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) 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) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) IOException(java.io.IOException) Test(org.junit.Test)

Example 48 with SortedMapIterator

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

the class VersioningIteratorTest method test1.

@Test
public void test1() {
    Text colf = new Text("a");
    Text colq = new Text("b");
    TreeMap<Key, Value> tm = new TreeMap<>();
    createTestData(tm, colf, colq);
    try {
        VersioningIterator it = new VersioningIterator();
        IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
        VersioningIterator.setMaxVersions(is, 3);
        it.init(new SortedMapIterator(tm), is.getOptions(), null);
        it.seek(new Range(), EMPTY_COL_FAMS, false);
        TreeMap<Key, Value> tmOut = iteratorOverTestData(it);
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            assertTrue(e.getValue().get().length == 8);
            assertTrue(16 < encoder.decode(e.getValue().get()));
        }
        assertTrue("size after keeping 3 versions was " + tmOut.size(), tmOut.size() == 6);
    } catch (IOException e) {
        assertFalse(true);
    } catch (Exception e) {
        log.error("{}", e.getMessage(), e);
        assertFalse(true);
    }
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) 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) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) IOException(java.io.IOException) Test(org.junit.Test)

Example 49 with SortedMapIterator

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

the class VersioningIteratorTest method test_maxLongExclusiveKey.

@Test
public void test_maxLongExclusiveKey() throws IOException {
    Text row = new Text("a");
    Text colf = new Text("b");
    Text colq = new Text("c");
    Text cv = new Text();
    TreeMap<Key, Value> tm = new TreeMap<>();
    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE), new Value("00".getBytes()));
    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE - 1), new Value("11".getBytes()));
    VersioningIterator it = new VersioningIterator();
    IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
    VersioningIterator.setMaxVersions(is, 1);
    it.init(new SortedMapIterator(tm), is.getOptions(), null);
    Key startKey = new Key(row, colf, colq, cv, Long.MAX_VALUE);
    Range testRange = new Range(startKey, false, startKey.followingKey(PartialKey.ROW), true);
    it.seek(testRange, EMPTY_COL_FAMS, false);
    assertFalse(it.hasTop());
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) 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) PartialKey(org.apache.accumulo.core.data.PartialKey) Test(org.junit.Test)

Example 50 with SortedMapIterator

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

the class VersioningIteratorTest method test_maxLongInclusiveKey.

@Test
public void test_maxLongInclusiveKey() throws IOException {
    Text row = new Text("a");
    Text colf = new Text("b");
    Text colq = new Text("c");
    Text cv = new Text();
    TreeMap<Key, Value> tm = new TreeMap<>();
    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE), new Value("00".getBytes()));
    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE - 1), new Value("11".getBytes()));
    VersioningIterator it = new VersioningIterator();
    IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
    VersioningIterator.setMaxVersions(is, 1);
    it.init(new SortedMapIterator(tm), is.getOptions(), null);
    Key startKey = new Key(row, colf, colq, cv, Long.MAX_VALUE);
    Range testRange = new Range(startKey, true, startKey.followingKey(PartialKey.ROW), true);
    it.seek(testRange, EMPTY_COL_FAMS, false);
    assertTrue(it.hasTop());
    assertTrue(it.getTopValue().contentEquals("00".getBytes()));
    it.next();
    assertFalse(it.hasTop());
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) 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) PartialKey(org.apache.accumulo.core.data.PartialKey) Test(org.junit.Test)

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