Search in sources :

Example 91 with SortedMapIterator

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

the class SourceSwitchingIteratorTest method testSetInterrupt.

public void testSetInterrupt() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    SortedMapIterator smi = new SortedMapIterator(tm1);
    TestDataSource tds = new TestDataSource(smi);
    SourceSwitchingIterator ssi = new SourceSwitchingIterator(tds, false);
    AtomicBoolean flag = new AtomicBoolean();
    ssi.setInterruptFlag(flag);
    assertSame(flag, tds.iflag);
    ssi.seek(new Range("r1"), new ArrayList<>(), false);
    testAndCallNext(ssi, "r1", "cf1", "cq1", 5, "v1", true);
    assertFalse(ssi.hasTop());
    flag.set(true);
    try {
        ssi.seek(new Range("r1"), new ArrayList<>(), false);
        fail("expected to see IterationInterruptedException");
    } catch (IterationInterruptedException iie) {
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Value(org.apache.accumulo.core.data.Value) IterationInterruptedException(org.apache.accumulo.core.iterators.IterationInterruptedException) 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) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 92 with SortedMapIterator

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

the class SourceSwitchingIteratorTest method test2.

public void test2() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq3", 5, "v2");
    put(tm1, "r2", "cf1", "cq1", 5, "v3");
    SortedMapIterator smi = new SortedMapIterator(tm1);
    TestDataSource tds = new TestDataSource(smi);
    SourceSwitchingIterator ssi = new SourceSwitchingIterator(tds);
    ssi.seek(new Range(), new ArrayList<>(), false);
    testAndCallNext(ssi, "r1", "cf1", "cq1", 5, "v1", true);
    TreeMap<Key, Value> tm2 = new TreeMap<>();
    put(tm2, "r1", "cf1", "cq1", 5, "v4");
    put(tm2, "r1", "cf1", "cq3", 5, "v5");
    put(tm2, "r2", "cf1", "cq1", 5, "v6");
    SortedMapIterator smi2 = new SortedMapIterator(tm2);
    TestDataSource tds2 = new TestDataSource(smi2);
    tds.next = tds2;
    testAndCallNext(ssi, "r1", "cf1", "cq3", 5, "v2", true);
    testAndCallNext(ssi, "r2", "cf1", "cq1", 5, "v6", true);
    assertFalse(ssi.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) 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) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 93 with SortedMapIterator

use of org.apache.accumulo.core.iterators.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".getBytes()));
    TimeSettingIterator tsi = new TimeSettingIterator(new SortedMapIterator(tm1), 50);
    tsi.seek(new Range(), new HashSet<>(), false);
    assertTrue(tsi.hasTop());
    final Key topKey = tsi.getTopKey();
    assertTrue("Expected the topKey to be the same object", k == topKey);
    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) 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 94 with SortedMapIterator

use of org.apache.accumulo.core.iterators.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".getBytes()));
    tm1.put(new Key("r1", "cf1", "cq1", Long.MAX_VALUE), new Value("v1".getBytes()));
    tm1.put(new Key("r1", "cf1", "cq1", 90l), new Value("v2".getBytes()));
    tm1.put(new Key("r1", "cf1", "cq1", 0l), new Value("v3".getBytes()));
    tm1.put(new Key("r2", "cf1", "cq1", 6l), new Value("v4".getBytes()));
    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) 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 95 with SortedMapIterator

use of org.apache.accumulo.core.iterators.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.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) 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