Search in sources :

Example 51 with SortedMapIterator

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

the class WholeColumnFamilyIteratorTest method testBug1.

@Test
public void testBug1() 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");
    SortedMap<Key, Value> map = new TreeMap<>();
    map.putAll(map1);
    map.putAll(map2);
    MultiIterator source = new MultiIterator(Collections.singletonList(new SortedMapIterator(map)), new Range(null, true, new Text("row1"), true));
    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);
    assertFalse(iter.hasTop());
}
Also used : MultiIterator(org.apache.accumulo.core.iteratorsImpl.system.MultiIterator) 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)

Example 52 with SortedMapIterator

use of org.apache.accumulo.core.iteratorsImpl.system.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, Set.of(), false);
        mi = new MultiIterator(iters, range);
        if (init)
            mi.seek(range, Set.of(), 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(end, i, "start=" + start + " end=" + end + " seekKey=" + seekKey + " endRow=" + endRow + " prevEndRow=" + prevEndRow + " init=" + init + " incrRow=" + incrRow + " maps=" + maps);
}
Also used : MultiIterator(org.apache.accumulo.core.iteratorsImpl.system.MultiIterator) ArrayList(java.util.ArrayList) Value(org.apache.accumulo.core.data.Value) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Example 53 with SortedMapIterator

use of org.apache.accumulo.core.iteratorsImpl.system.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"));
        sources.put(new Key(row.getBytes(), colf.getBytes(), colq.getBytes(), cv.getBytes(), Long.MIN_VALUE), new Value("11"));
        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());
        assertEquals(it.getTopValue(), new Value("00"));
        assertEquals(111L, it.getTopKey().getTimestamp());
        it.next();
        assertTrue(it.hasTop());
        assertEquals(it.getTopValue(), new Value("11"));
        assertEquals(111L, it.getTopKey().getTimestamp());
        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) TimeSettingIterator(org.apache.accumulo.core.iteratorsImpl.system.TimeSettingIterator) 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 54 with SortedMapIterator

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

the class BigDecimalCombinerTest method testMax.

@Test
public void testMax() throws IOException {
    ai = new BigDecimalCombiner.BigDecimalMaxCombiner();
    IteratorSetting is = new IteratorSetting(1, BigDecimalCombiner.BigDecimalMaxCombiner.class);
    Combiner.setColumns(is, columns);
    ai.init(new SortedMapIterator(tm1), is.getOptions(), CombinerTest.SCAN_IE);
    ai.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(ai.hasTop());
    assertEquals(CombinerTest.newKey(1, 1, 1, 3), ai.getTopKey());
    assertEquals(2.3, encoder.decode(ai.getTopValue().get()).doubleValue(), delta);
    verify();
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Test(org.junit.jupiter.api.Test)

Example 55 with SortedMapIterator

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

the class VisibilityFilterTest method testBadVisibility.

@Test
public void testBadVisibility() throws IOException {
    TreeMap<Key, Value> tm = new TreeMap<>();
    tm.put(new Key("r1", "cf1", "cq1", "A&"), new Value());
    SortedKeyValueIterator<Key, Value> filter = VisibilityFilter.wrap(new SortedMapIterator(tm), new Authorizations("A"), "".getBytes());
    filter.seek(new Range(), new HashSet<>(), false);
    assertFalse(filter.hasTop());
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) 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