Search in sources :

Example 91 with SortedMapIterator

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

the class WholeColumnFamilyIteratorTest method testEmptyStuff.

@Test
public void testEmptyStuff() throws IOException {
    SortedMap<Key, Value> map = new TreeMap<>();
    SortedMap<Key, Value> map2 = new TreeMap<>();
    final Map<Text, Boolean> toInclude = new HashMap<>();
    map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 1L), new Value("val1"));
    map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq2"), new Text("cv1"), 2L), new Value("val2"));
    map.put(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 3L), new Value("val3"));
    map.put(new Key(new Text("r2"), new Text("cf2"), new Text("cq1"), new Text("cv1"), 4L), new Value("val4"));
    map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 5L), new Value("val4"));
    map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv2"), 6L), new Value("val4"));
    map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 7L), new Value(""));
    map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text(""), 8L), new Value("val1"));
    map.put(new Key(new Text("r4"), new Text("cf1"), new Text(""), new Text("cv1"), 9L), new Value("val1"));
    map.put(new Key(new Text("r4"), new Text(""), new Text("cq1"), new Text("cv1"), 10L), new Value("val1"));
    map.put(new Key(new Text(""), new Text("cf1"), new Text("cq1"), new Text("cv1"), 11L), new Value("val1"));
    boolean b = true;
    int trueCount = 0;
    for (Key k : map.keySet()) {
        if (toInclude.containsKey(k.getRow())) {
            if (toInclude.get(k.getRow())) {
                map2.put(k, map.get(k));
            }
            continue;
        }
        b = !b;
        toInclude.put(k.getRow(), b);
        if (b) {
            trueCount++;
            map2.put(k, map.get(k));
        }
    }
    SortedMapIterator source = new SortedMapIterator(map);
    WholeColumnFamilyIterator iter = new WholeColumnFamilyIterator(source);
    SortedMap<Key, Value> resultMap = new TreeMap<>();
    iter.seek(new Range(), new ArrayList<>(), false);
    int numRows = 0;
    while (iter.hasTop()) {
        numRows++;
        Key rowKey = iter.getTopKey();
        Value rowValue = iter.getTopValue();
        resultMap.putAll(WholeColumnFamilyIterator.decodeColumnFamily(rowKey, rowValue));
        iter.next();
    }
    // we have 7 groups of row key/cf
    assertEquals(7, numRows);
    assertEquals(resultMap, map);
    WholeColumnFamilyIterator iter2 = new WholeColumnFamilyIterator(source) {

        @Override
        public boolean filter(Text row, List<Key> keys, List<Value> values) {
            return toInclude.get(row);
        }
    };
    resultMap.clear();
    iter2.seek(new Range(), new ArrayList<>(), false);
    numRows = 0;
    while (iter2.hasTop()) {
        numRows++;
        Key rowKey = iter2.getTopKey();
        Value rowValue = iter2.getTopValue();
        resultMap.putAll(WholeColumnFamilyIterator.decodeColumnFamily(rowKey, rowValue));
        iter2.next();
    }
    assertEquals(numRows, trueCount);
    assertEquals(resultMap, map2);
}
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) ArrayList(java.util.ArrayList) List(java.util.List) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 92 with SortedMapIterator

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

the class TimeSettingIteratorTest method test1.

@Test
public void test1() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    tm1.put(new Key("r0", "cf1", "cq1", 9L), new Value("v0"));
    tm1.put(new Key("r1", "cf1", "cq1", Long.MAX_VALUE), new Value("v1"));
    tm1.put(new Key("r1", "cf1", "cq1", 90L), new Value("v2"));
    tm1.put(new Key("r1", "cf1", "cq1", 0L), new Value("v3"));
    tm1.put(new Key("r2", "cf1", "cq1", 6L), new Value("v4"));
    TimeSettingIterator tsi = new TimeSettingIterator(new SortedMapIterator(tm1), 50);
    tsi.seek(new Range(new Key("r1", "cf1", "cq1", 50L), true, new Key("r1", "cf1", "cq1", 50L), true), new HashSet<>(), false);
    assertTrue(tsi.hasTop());
    assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
    assertEquals("v1", tsi.getTopValue().toString());
    tsi.next();
    assertTrue(tsi.hasTop());
    assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
    assertEquals("v2", tsi.getTopValue().toString());
    tsi.next();
    assertTrue(tsi.hasTop());
    assertEquals(new Key("r1", "cf1", "cq1", 50L), tsi.getTopKey());
    assertEquals("v3", tsi.getTopValue().toString());
    tsi.next();
    assertFalse(tsi.hasTop());
    tsi.seek(new Range(new Key("r1", "cf1", "cq1", 50L), false, null, true), new HashSet<>(), false);
    assertTrue(tsi.hasTop());
    assertEquals(new Key("r2", "cf1", "cq1", 50L), tsi.getTopKey());
    assertEquals("v4", tsi.getTopValue().toString());
    tsi.next();
    assertFalse(tsi.hasTop());
    tsi.seek(new Range(null, true, new Key("r1", "cf1", "cq1", 50L), false), new HashSet<>(), false);
    assertTrue(tsi.hasTop());
    assertEquals(new Key("r0", "cf1", "cq1", 50L), tsi.getTopKey());
    assertEquals("v0", tsi.getTopValue().toString());
    tsi.next();
    assertFalse(tsi.hasTop());
    tsi.seek(new Range(new Key("r1", "cf1", "cq1", 51L), true, new Key("r1", "cf1", "cq1", 50L), false), new HashSet<>(), false);
    assertFalse(tsi.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) 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 93 with SortedMapIterator

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

the class TimeSettingIteratorTest method testAvoidKeyCopy.

@Test
public void testAvoidKeyCopy() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    final Key k = new Key("r0", "cf1", "cq1", 9L);
    tm1.put(k, new Value("v0"));
    TimeSettingIterator tsi = new TimeSettingIterator(new SortedMapIterator(tm1), 50);
    tsi.seek(new Range(), new HashSet<>(), false);
    assertTrue(tsi.hasTop());
    final Key topKey = tsi.getTopKey();
    assertSame(k, topKey, "Expected the topKey to be the same object");
    assertEquals(new Key("r0", "cf1", "cq1", 50L), topKey);
    assertEquals("v0", tsi.getTopValue().toString());
    tsi.next();
    assertFalse(tsi.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) 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 94 with SortedMapIterator

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

the class BigDecimalCombinerTest method testSums.

@Test
public void testSums() throws IOException {
    ai = new BigDecimalCombiner.BigDecimalSummingCombiner();
    IteratorSetting is = new IteratorSetting(1, BigDecimalCombiner.BigDecimalSummingCombiner.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(-9.7, 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 95 with SortedMapIterator

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

the class BigDecimalCombinerTest method testMin.

@Test
public void testMin() throws IOException {
    ai = new BigDecimalCombiner.BigDecimalMinCombiner();
    IteratorSetting is = new IteratorSetting(1, BigDecimalCombiner.BigDecimalMinCombiner.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(-14.0, 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)

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