Search in sources :

Example 46 with SortedMapIterator

use of org.apache.accumulo.core.iteratorsImpl.system.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()) {
            assertEquals(8, e.getValue().get().length);
            assertTrue(16 < encoder.decode(e.getValue().get()));
        }
        assertEquals(0, tmOut.size(), "size after seeking past versions was " + tmOut.size());
        // 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()) {
            assertEquals(8, e.getValue().get().length);
            assertTrue(16 < encoder.decode(e.getValue().get()));
        }
        assertEquals(3, tmOut.size(), "size after seeking past versions was " + tmOut.size());
    } catch (IOException e) {
        fail();
    } catch (Exception e) {
        log.error("{}", e.getMessage(), e);
        fail();
    }
}
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.iteratorsImpl.system.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.jupiter.api.Test)

Example 47 with SortedMapIterator

use of org.apache.accumulo.core.iteratorsImpl.system.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"));
    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE - 1), new Value("11"));
    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.iteratorsImpl.system.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.jupiter.api.Test)

Example 48 with SortedMapIterator

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

the class VersioningIteratorTest method test2.

@Test
public void test2() {
    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 only get two keys for row 1
        // since we are seeking to the middle of the most recent
        // three keys
        Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 18);
        it.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
        TreeMap<Key, Value> tmOut = iteratorOverTestData(it);
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            assertEquals(8, e.getValue().get().length);
            assertTrue(16 < encoder.decode(e.getValue().get()));
        }
        assertEquals(2, tmOut.size(), "size after keeping 2 versions was " + tmOut.size());
    } catch (IOException e) {
        fail();
    } catch (Exception e) {
        log.error("{}", e.getMessage(), e);
        fail();
    }
}
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.iteratorsImpl.system.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.jupiter.api.Test)

Example 49 with SortedMapIterator

use of org.apache.accumulo.core.iteratorsImpl.system.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());
    assertEquals(18, it.getTopKey().getTimestamp());
    assertTrue(it2.hasTop());
    assertEquals(18, it2.getTopKey().getTimestamp());
}
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.iteratorsImpl.system.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.jupiter.api.Test)

Example 50 with SortedMapIterator

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

the class WholeColumnFamilyIteratorTest method testContinue.

@Test
public void testContinue() throws Exception {
    SortedMap<Key, Value> map1 = new TreeMap<>();
    pkv(map1, "row1", "cf1", "cq1", "cv1", 5, "foo");
    pkv(map1, "row1", "cf1", "cq2", "cv1", 6, "bar");
    SortedMap<Key, Value> map2 = new TreeMap<>();
    pkv(map2, "row2", "cf1", "cq1", "cv1", 5, "foo");
    pkv(map2, "row2", "cf1", "cq2", "cv1", 6, "bar");
    SortedMap<Key, Value> map3 = new TreeMap<>();
    pkv(map3, "row3", "cf1", "cq1", "cv1", 5, "foo");
    pkv(map3, "row3", "cf1", "cq2", "cv1", 6, "bar");
    SortedMap<Key, Value> map = new TreeMap<>();
    map.putAll(map1);
    map.putAll(map2);
    map.putAll(map3);
    SortedMapIterator source = new SortedMapIterator(map);
    WholeColumnFamilyIterator iter = new WholeColumnFamilyIterator(source);
    Range range = new Range(new Text("row1"), true, new Text("row2"), true);
    iter.seek(range, new ArrayList<>(), false);
    assertTrue(iter.hasTop());
    assertEquals(map1, WholeColumnFamilyIterator.decodeColumnFamily(iter.getTopKey(), iter.getTopValue()));
    // simulate something continuing using the last key from the iterator
    // this is what client and server code will do
    range = new Range(iter.getTopKey(), false, range.getEndKey(), range.isEndKeyInclusive());
    iter.seek(range, new ArrayList<>(), false);
    assertTrue(iter.hasTop());
    assertEquals(map2, WholeColumnFamilyIterator.decodeColumnFamily(iter.getTopKey(), iter.getTopValue()));
    iter.next();
    assertFalse(iter.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) 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