Search in sources :

Example 1 with ValueFormatException

use of org.apache.accumulo.core.iterators.ValueFormatException 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

ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 Key (org.apache.accumulo.core.data.Key)1 Range (org.apache.accumulo.core.data.Range)1 Value (org.apache.accumulo.core.data.Value)1 SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)1 ValueFormatException (org.apache.accumulo.core.iterators.ValueFormatException)1 Test (org.junit.Test)1