Search in sources :

Example 71 with SortedMapIterator

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

the class RowDeletingIteratorTest method test3.

public void test3() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "", "", 10, RowDeletingIterator.DELETE_ROW_VALUE);
    put(tm1, "r1", "", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r2", "", "cq1", 5, "v1");
    put(tm1, "r2", "cf1", "cq1", 5, "v1");
    RowDeletingIterator rdi = new RowDeletingIterator();
    rdi.init(new ColumnFamilySkippingIterator(new SortedMapIterator(tm1)), null, new TestIE(IteratorScope.scan, false));
    HashSet<ByteSequence> cols = new HashSet<>();
    cols.add(new ArrayByteSequence("cf1".getBytes()));
    rdi.seek(new Range(), cols, true);
    testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
    cols.clear();
    cols.add(new ArrayByteSequence("".getBytes()));
    rdi.seek(new Range(), cols, false);
    testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
    cols.clear();
    rdi.seek(new Range(), cols, false);
    testAssertions(rdi, "r2", "", "cq1", 5, "v1");
    rdi.next();
    testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
}
Also used : ColumnFamilySkippingIterator(org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Value(org.apache.accumulo.core.data.Value) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet)

Example 72 with SortedMapIterator

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

the class RowDeletingIteratorTest method test1.

public void test1() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "", "", 10, RowDeletingIterator.DELETE_ROW_VALUE);
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq3", 5, "v1");
    put(tm1, "r2", "cf1", "cq1", 5, "v1");
    RowDeletingIterator rdi = new RowDeletingIterator();
    rdi.init(new SortedMapIterator(tm1), null, new TestIE(IteratorScope.scan, false));
    rdi.seek(new Range(), new ArrayList<>(), false);
    testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
    for (int i = 0; i < 5; i++) {
        rdi.seek(new Range(newKey("r1", "cf1", "cq" + i, 5), null), new ArrayList<>(), false);
        testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
    }
    rdi.seek(new Range(newKey("r11", "cf1", "cq1", 5), null), new ArrayList<>(), false);
    testAssertions(rdi, "r2", "cf1", "cq1", 5, "v1");
    put(tm1, "r2", "", "", 10, RowDeletingIterator.DELETE_ROW_VALUE);
    rdi.seek(new Range(), new ArrayList<>(), false);
    assertFalse(rdi.hasTop());
    for (int i = 0; i < 5; i++) {
        rdi.seek(new Range(newKey("r1", "cf1", "cq" + i, 5), null), new ArrayList<>(), false);
        assertFalse(rdi.hasTop());
    }
    put(tm1, "r0", "cf1", "cq1", 5, "v1");
    rdi.seek(new Range(), new ArrayList<>(), false);
    testAssertions(rdi, "r0", "cf1", "cq1", 5, "v1");
    rdi.next();
    assertFalse(rdi.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)

Example 73 with SortedMapIterator

use of org.apache.accumulo.core.iterators.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.getTopKey(), 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.getTopKey(), 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.iterators.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.Test)

Example 74 with SortedMapIterator

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

the class RowEncodingIteratorTest method testEncodeSome.

@Test(expected = BufferOverflowException.class)
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());
    iter.seek(range, new ArrayList<>(), false);
// BufferOverflowException should be thrown as RowEncodingIterator can't fit the whole row into its buffer.
}
Also used : HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.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.Test)

Example 75 with SortedMapIterator

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

the class RowFilterTest method test1.

@Test
public void test1() throws Exception {
    ColumnFamilySkippingIterator source = new ColumnFamilySkippingIterator(new SortedMapIterator(createKeyValues()));
    RowFilter filter = new SummingRowFilter();
    filter.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
    filter.seek(new Range(), Collections.emptySet(), false);
    assertEquals(new HashSet<>(Arrays.asList("2", "3")), getRows(filter));
    ByteSequence cf = new ArrayByteSequence("cf2");
    filter.seek(new Range(), ImmutableSet.of(cf), true);
    assertEquals(new HashSet<>(Arrays.asList("1", "3", "0", "4")), getRows(filter));
    filter.seek(new Range("0", "4"), Collections.emptySet(), false);
    assertEquals(new HashSet<>(Arrays.asList("2", "3")), getRows(filter));
    filter.seek(new Range("2"), Collections.emptySet(), false);
    assertEquals(new HashSet<>(Arrays.asList("2")), getRows(filter));
    filter.seek(new Range("4"), Collections.emptySet(), false);
    assertEquals(new HashSet<String>(), getRows(filter));
    filter.seek(new Range("4"), ImmutableSet.of(cf), true);
    assertEquals(new HashSet<>(Arrays.asList("4")), getRows(filter));
}
Also used : ColumnFamilySkippingIterator(org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator) DefaultIteratorEnvironment(org.apache.accumulo.core.iterators.DefaultIteratorEnvironment) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) 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