Search in sources :

Example 66 with SortedMapIterator

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

the class CombinerTest method runDeleteHandlingTest.

private void runDeleteHandlingTest(TreeMap<Key, Value> input, TreeMap<Key, Value> expected, Boolean rofco, IteratorEnvironment env, boolean expectedLog, boolean clearLogMsgCache) throws Exception {
    boolean deepCopy = expected == null;
    if (clearLogMsgCache) {
        CombinerTestUtil.clearLogCache();
    }
    Combiner ai = new SummingCombiner();
    IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
    SummingCombiner.setEncodingType(is, LongCombiner.StringEncoder.class);
    Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
    if (rofco != null) {
        Combiner.setReduceOnFullCompactionOnly(is, rofco);
    }
    ai.init(new SortedMapIterator(input), is.getOptions(), env);
    if (deepCopy)
        assertEquals(expected, readAll(ai.deepCopy(env)));
    assertEquals(expected, readAll(ai));
    long logSize = CombinerTestUtil.cacheSize();
    if (expectedLog) {
        assertTrue(logSize > 0, "Expected >0 log messages, but got : " + logSize);
    } else {
        assertEquals(0, logSize, "Expected 0 log messages, but got : " + logSize);
    }
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) LongCombiner(org.apache.accumulo.core.iterators.LongCombiner) LongCombiner(org.apache.accumulo.core.iterators.LongCombiner) TypedValueCombiner(org.apache.accumulo.core.iterators.TypedValueCombiner) Combiner(org.apache.accumulo.core.iterators.Combiner) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator)

Example 67 with SortedMapIterator

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

the class CombinerTest method test5.

@Test
public void test5() throws IOException {
    Encoder<Long> encoder = LongCombiner.STRING_ENCODER;
    // try aggregating across multiple data sets that contain
    // the exact same keys w/ different values
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    newKeyValue(tm1, 1, 1, 1, 1, false, 2L, encoder);
    TreeMap<Key, Value> tm2 = new TreeMap<>();
    newKeyValue(tm2, 1, 1, 1, 1, false, 3L, encoder);
    TreeMap<Key, Value> tm3 = new TreeMap<>();
    newKeyValue(tm3, 1, 1, 1, 1, false, 4L, encoder);
    Combiner ai = new SummingCombiner();
    IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
    LongCombiner.setEncodingType(is, StringEncoder.class);
    Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
    List<SortedKeyValueIterator<Key, Value>> sources = new ArrayList<>(3);
    sources.add(new SortedMapIterator(tm1));
    sources.add(new SortedMapIterator(tm2));
    sources.add(new SortedMapIterator(tm3));
    MultiIterator mi = new MultiIterator(sources, true);
    ai.init(mi, is.getOptions(), SCAN_IE);
    ai.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(ai.hasTop());
    assertEquals(newKey(1, 1, 1, 1), ai.getTopKey());
    assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
}
Also used : MultiIterator(org.apache.accumulo.core.iteratorsImpl.system.MultiIterator) ArrayList(java.util.ArrayList) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) LongCombiner(org.apache.accumulo.core.iterators.LongCombiner) TypedValueCombiner(org.apache.accumulo.core.iterators.TypedValueCombiner) Combiner(org.apache.accumulo.core.iterators.Combiner) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 68 with SortedMapIterator

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

the class RowEncodingIteratorTest method testEncodeSome.

@Test
public void testEncodeSome() throws IOException {
    byte[] kbVal = new byte[1024];
    // This code is shamelessly borrowed from the WholeRowIteratorTest.
    SortedMap<Key, Value> map1 = new TreeMap<>();
    pkv(map1, "row1", "cf1", "cq1", "cv1", 5, kbVal);
    pkv(map1, "row1", "cf1", "cq2", "cv1", 6, kbVal);
    SortedMap<Key, Value> map = new TreeMap<>();
    map.putAll(map1);
    SortedMapIterator src = new SortedMapIterator(map);
    Range range = new Range(new Text("row1"), true, new Text("row2"), true);
    RowEncodingIteratorImpl iter = new RowEncodingIteratorImpl();
    Map<String, String> bigBufferOpts = new HashMap<>();
    bigBufferOpts.put(RowEncodingIterator.MAX_BUFFER_SIZE_OPT, "1K");
    iter.init(src, bigBufferOpts, new DummyIteratorEnv());
    assertThrows(IllegalArgumentException.class, () -> iter.seek(range, new ArrayList<>(), false));
// IllegalArgumentException should be thrown as we can't fit the whole row into its buffer
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 69 with SortedMapIterator

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

the class RowEncodingIteratorTest method testEncodeAll.

@Test
public void testEncodeAll() throws IOException {
    byte[] kbVal = new byte[1024];
    // This code is shamelessly borrowed from the WholeRowIteratorTest.
    SortedMap<Key, Value> map1 = new TreeMap<>();
    pkv(map1, "row1", "cf1", "cq1", "cv1", 5, kbVal);
    pkv(map1, "row1", "cf1", "cq2", "cv1", 6, kbVal);
    SortedMap<Key, Value> map2 = new TreeMap<>();
    pkv(map2, "row2", "cf1", "cq1", "cv1", 5, kbVal);
    pkv(map2, "row2", "cf1", "cq2", "cv1", 6, kbVal);
    SortedMap<Key, Value> map3 = new TreeMap<>();
    pkv(map3, "row3", "cf1", "cq1", "cv1", 5, kbVal);
    pkv(map3, "row3", "cf1", "cq2", "cv1", 6, kbVal);
    SortedMap<Key, Value> map = new TreeMap<>();
    map.putAll(map1);
    map.putAll(map2);
    map.putAll(map3);
    SortedMapIterator src = new SortedMapIterator(map);
    Range range = new Range(new Text("row1"), true, new Text("row2"), true);
    RowEncodingIteratorImpl iter = new RowEncodingIteratorImpl();
    Map<String, String> bigBufferOpts = new HashMap<>();
    bigBufferOpts.put(RowEncodingIterator.MAX_BUFFER_SIZE_OPT, "3K");
    iter.init(src, bigBufferOpts, new DummyIteratorEnv());
    iter.seek(range, new ArrayList<>(), false);
    assertTrue(iter.hasTop());
    assertEquals(map1, RowEncodingIteratorImpl.decodeRow(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, RowEncodingIteratorImpl.decodeRow(iter.getTopValue()));
    iter.next();
    assertFalse(iter.hasTop());
}
Also used : HashMap(java.util.HashMap) 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) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 70 with SortedMapIterator

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

the class FirstEntryInRowIteratorTest method process.

private static long process(TreeMap<Key, Value> sourceMap, TreeMap<Key, Value> resultMap, Range range, IteratorSetting iteratorSetting) throws IOException {
    SortedMapIterator source = new SortedMapIterator(sourceMap);
    CountingIterator counter = new CountingIterator(source);
    FirstEntryInRowIterator feiri = new FirstEntryInRowIterator();
    IteratorEnvironment env = new DefaultIteratorEnvironment();
    feiri.init(counter, iteratorSetting.getOptions(), env);
    feiri.seek(range, Set.of(), false);
    while (feiri.hasTop()) {
        resultMap.put(feiri.getTopKey(), feiri.getTopValue());
        feiri.next();
    }
    return counter.getCount();
}
Also used : CountingIterator(org.apache.accumulo.core.iteratorsImpl.system.CountingIterator) SortedMapIterator(org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator)

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