Search in sources :

Example 1 with SortedMapIterator

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

the class CombinerTest method test7.

@Test
public void test7() throws IOException {
    Encoder<Long> encoder = LongCombiner.FIXED_LEN_ENCODER;
    // test that delete is not aggregated
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    newKeyValue(tm1, 1, 1, 1, 2, true, 0l, encoder);
    newKeyValue(tm1, 1, 1, 1, 3, false, 4l, encoder);
    newKeyValue(tm1, 1, 1, 1, 4, false, 3l, encoder);
    Combiner ai = new SummingCombiner();
    IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
    LongCombiner.setEncodingType(is, SummingCombiner.Type.FIXEDLEN);
    Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
    ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
    ai.seek(newRow(1, 1, 1, 4, true), EMPTY_COL_FAMS, false);
    assertTrue(ai.hasTop());
    assertEquals(newKey(1, 1, 1, 4), ai.getTopKey());
    assertEquals("7", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertTrue(ai.hasTop());
    assertEquals(newKey(1, 1, 1, 2, true), ai.getTopKey());
    assertEquals("0", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertFalse(ai.hasTop());
    tm1 = new TreeMap<>();
    newKeyValue(tm1, 1, 1, 1, 2, true, 0l, encoder);
    ai = new SummingCombiner();
    ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
    ai.seek(newRow(1, 1, 1, 4, true), EMPTY_COL_FAMS, false);
    assertTrue(ai.hasTop());
    assertEquals(newKey(1, 1, 1, 2, true), ai.getTopKey());
    assertEquals("0", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertFalse(ai.hasTop());
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) 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.iterators.SortedMapIterator) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 2 with SortedMapIterator

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

the class CombinerTest method test6.

@Test
public void test6() throws IOException {
    Encoder<Long> encoder = LongCombiner.VAR_LEN_ENCODER;
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    // keys that aggregate
    newKeyValue(tm1, 1, 1, 1, 1, false, 2l, encoder);
    newKeyValue(tm1, 1, 1, 1, 2, false, 3l, encoder);
    newKeyValue(tm1, 1, 1, 1, 3, false, 4l, encoder);
    Combiner ai = new SummingCombiner();
    IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
    LongCombiner.setEncodingType(is, VarLenEncoder.class.getName());
    Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
    ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
    // try seeking to the beginning of a key that aggregates
    ai.seek(newRow(1, 1, 1, 3, false), EMPTY_COL_FAMS, false);
    assertFalse(ai.hasTop());
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) LongCombiner(org.apache.accumulo.core.iterators.LongCombiner) TypedValueCombiner(org.apache.accumulo.core.iterators.TypedValueCombiner) Combiner(org.apache.accumulo.core.iterators.Combiner) VarLenEncoder(org.apache.accumulo.core.iterators.LongCombiner.VarLenEncoder) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 3 with SortedMapIterator

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

the class CombinerTest method test4.

@Test
public void test4() throws IOException {
    Encoder<Long> encoder = LongCombiner.STRING_ENCODER;
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    // keys that do not aggregate
    newKeyValue(tm1, 0, 0, 1, 1, false, 7l, encoder);
    // keys that aggregate
    newKeyValue(tm1, 1, 1, 1, 1, false, 2l, encoder);
    newKeyValue(tm1, 1, 1, 1, 2, false, 3l, encoder);
    newKeyValue(tm1, 1, 1, 1, 3, false, 4l, encoder);
    // keys that do not aggregate
    newKeyValue(tm1, 2, 2, 1, 1, false, 2l, encoder);
    newKeyValue(tm1, 2, 2, 1, 2, false, 3l, encoder);
    Combiner ai = new SummingCombiner();
    IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
    LongCombiner.setEncodingType(is, SummingCombiner.Type.STRING);
    Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
    ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
    ai.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(ai.hasTop());
    assertEquals(newKey(0, 0, 1, 1), ai.getTopKey());
    assertEquals("7", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertTrue(ai.hasTop());
    assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
    assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertTrue(ai.hasTop());
    assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
    assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertTrue(ai.hasTop());
    assertEquals(newKey(2, 2, 1, 1), ai.getTopKey());
    assertEquals("2", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertFalse(ai.hasTop());
    // seek test
    ai.seek(newRow(0, 0, 1, 0), EMPTY_COL_FAMS, false);
    assertTrue(ai.hasTop());
    assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
    assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertTrue(ai.hasTop());
    assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
    assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
    // seek after key that aggregates
    ai.seek(newRow(1, 1, 1, 2), EMPTY_COL_FAMS, false);
    assertTrue(ai.hasTop());
    assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
    assertEquals("3", encoder.decode(ai.getTopValue().get()).toString());
    // combine all columns
    is = new IteratorSetting(1, SummingCombiner.class);
    LongCombiner.setEncodingType(is, SummingCombiner.Type.STRING);
    Combiner.setCombineAllColumns(is, true);
    ai.init(new SortedMapIterator(tm1), is.getOptions(), SCAN_IE);
    ai.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(ai.hasTop());
    assertEquals(newKey(0, 0, 1, 1), ai.getTopKey());
    assertEquals("7", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertTrue(ai.hasTop());
    assertEquals(newKey(1, 1, 1, 3), ai.getTopKey());
    assertEquals("9", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertTrue(ai.hasTop());
    assertEquals(newKey(2, 2, 1, 2), ai.getTopKey());
    assertEquals("5", encoder.decode(ai.getTopValue().get()).toString());
    ai.next();
    assertFalse(ai.hasTop());
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) 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.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 4 with SortedMapIterator

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

the class CombinerTest method valueIteratorTest.

@Test
public void valueIteratorTest() throws IOException {
    TreeMap<Key, Value> tm = new TreeMap<>();
    tm.put(new Key("r", "f", "q", 1), new Value("1".getBytes()));
    tm.put(new Key("r", "f", "q", 2), new Value("2".getBytes()));
    SortedMapIterator smi = new SortedMapIterator(tm);
    smi.seek(new Range(), EMPTY_COL_FAMS, false);
    ValueIterator iter = new ValueIterator(smi);
    assertEquals(iter.next().toString(), "2");
    assertEquals(iter.next().toString(), "1");
    assertFalse(iter.hasNext());
}
Also used : Value(org.apache.accumulo.core.data.Value) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) ValueIterator(org.apache.accumulo.core.iterators.Combiner.ValueIterator) 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 5 with SortedMapIterator

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

the class CombinerTest method testLossyOption.

/**
 * Tests the Lossy option will ignore errors in TypedValueCombiner. Uses SummingArrayCombiner to generate error.
 */
@Test
public void testLossyOption() throws IOException, IllegalAccessException, InstantiationException {
    Encoder<List<Long>> encoder = new SummingArrayCombiner.VarLongArrayEncoder();
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    // keys that aggregate
    tm1.put(newKey(1, 1, 1, 1, false), new Value("badValue"));
    newKeyValue(tm1, 1, 1, 1, 2, false, nal(3l, 4l, 5l), encoder);
    newKeyValue(tm1, 1, 1, 1, 3, false, nal(), encoder);
    SummingArrayCombiner summingArrayCombiner = new SummingArrayCombiner();
    IteratorSetting iteratorSetting = new IteratorSetting(1, SummingArrayCombiner.class);
    SummingArrayCombiner.setEncodingType(iteratorSetting, SummingArrayCombiner.Type.VARLEN);
    Combiner.setColumns(iteratorSetting, Collections.singletonList(new IteratorSetting.Column("cf001")));
    // lossy = true so ignore bad value
    TypedValueCombiner.setLossyness(iteratorSetting, true);
    assertTrue(summingArrayCombiner.validateOptions(iteratorSetting.getOptions()));
    summingArrayCombiner.init(new SortedMapIterator(tm1), iteratorSetting.getOptions(), SCAN_IE);
    summingArrayCombiner.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(summingArrayCombiner.hasTop());
    assertEquals(newKey(1, 1, 1, 3), summingArrayCombiner.getTopKey());
    assertBytesEqual(encoder.encode(nal(3l, 4l, 5l)), summingArrayCombiner.getTopValue().get());
    summingArrayCombiner.next();
    assertFalse(summingArrayCombiner.hasTop());
    // lossy = false throw error for bad value
    TypedValueCombiner.setLossyness(iteratorSetting, false);
    assertTrue(summingArrayCombiner.validateOptions(iteratorSetting.getOptions()));
    summingArrayCombiner.init(new SortedMapIterator(tm1), iteratorSetting.getOptions(), SCAN_IE);
    try {
        summingArrayCombiner.seek(new Range(), EMPTY_COL_FAMS, false);
        Assert.fail("ValueFormatException should have been thrown");
    } catch (ValueFormatException e) {
    }
}
Also used : TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) ValueFormatException(org.apache.accumulo.core.iterators.ValueFormatException) ArrayList(java.util.ArrayList) List(java.util.List) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

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