Search in sources :

Example 31 with SortedMapIterator

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

the class SourceSwitchingIteratorTest method test3.

public void test3() throws Exception {
    // test switching after a row
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq2", 5, "v2");
    put(tm1, "r1", "cf1", "cq3", 5, "v3");
    put(tm1, "r1", "cf1", "cq4", 5, "v4");
    put(tm1, "r3", "cf1", "cq1", 5, "v5");
    put(tm1, "r3", "cf1", "cq2", 5, "v6");
    SortedMapIterator smi = new SortedMapIterator(tm1);
    TestDataSource tds = new TestDataSource(smi);
    SourceSwitchingIterator ssi = new SourceSwitchingIterator(tds, true);
    ssi.seek(new Range(), new ArrayList<>(), false);
    testAndCallNext(ssi, "r1", "cf1", "cq1", 5, "v1", true);
    TreeMap<Key, Value> tm2 = new TreeMap<>(tm1);
    // should not see this because it should not switch until the row is finished
    put(tm2, "r1", "cf1", "cq5", 5, "v7");
    // should see this new row after it switches
    put(tm2, "r2", "cf1", "cq1", 5, "v8");
    // setup a new data source, but it should not switch until the current row is finished
    SortedMapIterator smi2 = new SortedMapIterator(tm2);
    TestDataSource tds2 = new TestDataSource(smi2);
    tds.next = tds2;
    testAndCallNext(ssi, "r1", "cf1", "cq2", 5, "v2", true);
    testAndCallNext(ssi, "r1", "cf1", "cq3", 5, "v3", true);
    testAndCallNext(ssi, "r1", "cf1", "cq4", 5, "v4", true);
    testAndCallNext(ssi, "r2", "cf1", "cq1", 5, "v8", true);
    testAndCallNext(ssi, "r3", "cf1", "cq1", 5, "v5", true);
    testAndCallNext(ssi, "r3", "cf1", "cq2", 5, "v6", true);
}
Also used : Value(org.apache.accumulo.core.data.Value) 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)

Example 32 with SortedMapIterator

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

the class SourceSwitchingIteratorTest method test5.

public void test5() throws Exception {
    // esnure switchNow() works w/ deepCopy()
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq2", 5, "v2");
    SortedMapIterator smi = new SortedMapIterator(tm1);
    TestDataSource tds = new TestDataSource(smi);
    SourceSwitchingIterator ssi = new SourceSwitchingIterator(tds, false);
    SortedKeyValueIterator<Key, Value> dc1 = ssi.deepCopy(null);
    TreeMap<Key, Value> tm2 = new TreeMap<>();
    put(tm2, "r1", "cf1", "cq1", 6, "v3");
    put(tm2, "r2", "cf1", "cq2", 6, "v4");
    SortedMapIterator smi2 = new SortedMapIterator(tm2);
    TestDataSource tds2 = new TestDataSource(smi2);
    tds.setNext(tds2);
    ssi.switchNow();
    ssi.seek(new Range("r1"), new ArrayList<>(), false);
    dc1.seek(new Range("r2"), new ArrayList<>(), false);
    testAndCallNext(ssi, "r1", "cf1", "cq1", 6, "v3", true);
    assertFalse(ssi.hasTop());
    testAndCallNext(dc1, "r2", "cf1", "cq2", 6, "v4", true);
    assertFalse(dc1.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) 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)

Example 33 with SortedMapIterator

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

the class SourceSwitchingIteratorTest method test4.

public void test4() throws Exception {
    // ensure switch is done on initial seek
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq2", 5, "v2");
    SortedMapIterator smi = new SortedMapIterator(tm1);
    TestDataSource tds = new TestDataSource(smi);
    SourceSwitchingIterator ssi = new SourceSwitchingIterator(tds, false);
    TreeMap<Key, Value> tm2 = new TreeMap<>();
    put(tm2, "r1", "cf1", "cq1", 6, "v3");
    put(tm2, "r1", "cf1", "cq2", 6, "v4");
    SortedMapIterator smi2 = new SortedMapIterator(tm2);
    TestDataSource tds2 = new TestDataSource(smi2);
    tds.next = tds2;
    ssi.seek(new Range(), new ArrayList<>(), false);
    testAndCallNext(ssi, "r1", "cf1", "cq1", 6, "v3", true);
    testAndCallNext(ssi, "r1", "cf1", "cq2", 6, "v4", true);
}
Also used : Value(org.apache.accumulo.core.data.Value) 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)

Example 34 with SortedMapIterator

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

the class TimeSettingIteratorTest method testEndKeyRangeAtMinLongValue.

@Test
public void testEndKeyRangeAtMinLongValue() throws IOException {
    Text row = new Text("a");
    Text colf = new Text("b");
    Text colq = new Text("c");
    Text cv = new Text();
    for (boolean inclusiveEndRange : new boolean[] { true, false }) {
        TreeMap<Key, Value> sources = new TreeMap<>();
        sources.put(new Key(row.getBytes(), colf.getBytes(), colq.getBytes(), cv.getBytes(), Long.MIN_VALUE, true), new Value("00".getBytes()));
        sources.put(new Key(row.getBytes(), colf.getBytes(), colq.getBytes(), cv.getBytes(), Long.MIN_VALUE), new Value("11".getBytes()));
        TimeSettingIterator it = new TimeSettingIterator(new SortedMapIterator(sources), 111L);
        IteratorSetting is = new IteratorSetting(1, TimeSettingIterator.class);
        it.init(null, is.getOptions(), null);
        Key startKey = new Key();
        Key endKey = new Key(row, colf, colq, cv, Long.MIN_VALUE);
        Range testRange = new Range(startKey, false, endKey, inclusiveEndRange);
        it.seek(testRange, new HashSet<>(), false);
        assertTrue(it.hasTop());
        assertTrue(it.getTopValue().equals(new Value("00".getBytes())));
        assertTrue(it.getTopKey().getTimestamp() == 111L);
        it.next();
        assertTrue(it.hasTop());
        assertTrue(it.getTopValue().equals(new Value("11".getBytes())));
        assertTrue(it.getTopKey().getTimestamp() == 111L);
        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) Test(org.junit.Test)

Example 35 with SortedMapIterator

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

the class VisibilityFilterTest method testBadVisibility.

public void testBadVisibility() throws IOException {
    TreeMap<Key, Value> tm = new TreeMap<>();
    tm.put(new Key("r1", "cf1", "cq1", "A&"), new Value(new byte[0]));
    SortedKeyValueIterator<Key, Value> filter = VisibilityFilter.wrap(new SortedMapIterator(tm), new Authorizations("A"), "".getBytes());
    // suppress logging
    Level prevLevel = Logger.getLogger(VisibilityFilter.class).getLevel();
    Logger.getLogger(VisibilityFilter.class).setLevel(Level.FATAL);
    filter.seek(new Range(), new HashSet<>(), false);
    assertFalse(filter.hasTop());
    Logger.getLogger(VisibilityFilter.class).setLevel(prevLevel);
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) Value(org.apache.accumulo.core.data.Value) Level(org.apache.log4j.Level) 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