Search in sources :

Example 41 with SortedMapIterator

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

the class ColumnSliceFilterTest method testNullStart.

@Test
public void testNullStart() throws IOException {
    ColumnSliceFilter.setSlice(is, null, "20080204");
    columnSliceFilter.validateOptions(is.getOptions());
    columnSliceFilter.init(new SortedMapIterator(TEST_DATA), is.getOptions(), iteratorEnvironment);
    columnSliceFilter.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(columnSliceFilter.hasTop());
    assertTrue(columnSliceFilter.getTopKey().equals(KEY_2));
    columnSliceFilter.next();
    assertTrue(columnSliceFilter.hasTop());
    assertTrue(columnSliceFilter.getTopKey().equals(KEY_1));
    columnSliceFilter.next();
    assertTrue(columnSliceFilter.hasTop());
    assertTrue(columnSliceFilter.getTopKey().equals(KEY_3));
    columnSliceFilter.next();
    assertTrue(columnSliceFilter.hasTop());
    assertTrue(columnSliceFilter.getTopKey().equals(KEY_6));
    columnSliceFilter.next();
    assertFalse(columnSliceFilter.hasTop());
}
Also used : SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Test(org.junit.Test)

Example 42 with SortedMapIterator

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

the class RowFilterTest method deepCopyCopiesTheSource.

@Test
public void deepCopyCopiesTheSource() throws Exception {
    SortedMapIterator source = new SortedMapIterator(createKeyValues());
    RowFilter filter = new RowZeroOrOneFilter();
    filter.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
    filter.seek(new Range(), Collections.emptySet(), false);
    // Save off the first key and value
    Key firstKey = filter.getTopKey();
    Value firstValue = filter.getTopValue();
    // Assert that the row is valid given our filter
    assertEquals("0", firstKey.getRow().toString());
    // Read some extra data, just making sure it's all valid
    Key lastKeyRead = null;
    for (int i = 0; i < 5; i++) {
        filter.next();
        lastKeyRead = filter.getTopKey();
        assertEquals("0", lastKeyRead.getRow().toString());
    }
    // Make a copy of the original RowFilter
    RowFilter copy = (RowFilter) filter.deepCopy(new DefaultIteratorEnvironment());
    // Because it's a copy, we should be able to safely seek this one without affecting the original
    copy.seek(new Range(), Collections.emptySet(), false);
    assertTrue("deepCopy'ed RowFilter did not have a top key", copy.hasTop());
    Key firstKeyFromCopy = copy.getTopKey();
    Value firstValueFromCopy = copy.getTopValue();
    // Verify that we got the same first k-v pair we did earlier
    assertEquals(firstKey, firstKeyFromCopy);
    assertEquals(firstValue, firstValueFromCopy);
    filter.next();
    Key finalKeyRead = filter.getTopKey();
    // Make sure we got a Key that was greater than the last Key we read from the original RowFilter
    assertTrue("Expected next key read to be greater than the previous after deepCopy", lastKeyRead.compareTo(finalKeyRead) < 0);
}
Also used : DefaultIteratorEnvironment(org.apache.accumulo.core.iterators.DefaultIteratorEnvironment) Value(org.apache.accumulo.core.data.Value) 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 43 with SortedMapIterator

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

the class RowFilterTest method testChainedRowFilters.

@Test
public void testChainedRowFilters() throws Exception {
    SortedMapIterator source = new SortedMapIterator(createKeyValues());
    RowFilter filter0 = new TrueFilter();
    filter0.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
    RowFilter filter = new TrueFilter();
    filter.init(filter0, Collections.emptyMap(), new DefaultIteratorEnvironment());
    filter.seek(new Range(), Collections.emptySet(), false);
    assertEquals(new HashSet<>(Arrays.asList("0", "1", "2", "3", "4")), getRows(filter));
}
Also used : DefaultIteratorEnvironment(org.apache.accumulo.core.iterators.DefaultIteratorEnvironment) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Test(org.junit.Test)

Example 44 with SortedMapIterator

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

the class TestCfCqSlice method testStackedFilters.

@Test
public void testStackedFilters() throws Exception {
    Map<String, String> firstOpts = new HashMap<>();
    Map<String, String> secondOpts = new HashMap<>();
    boolean[][][] foundKvs = new boolean[LR_DIM][LR_DIM][LR_DIM];
    long sliceMinCf = 20;
    long sliceMaxCf = 25;
    long sliceMinCq = 30;
    long sliceMaxCq = 35;
    assertTrue("slice param must be less than LR_DIM", sliceMinCf < LR_DIM);
    assertTrue("slice param must be less than LR_DIM", sliceMinCq < LR_DIM);
    assertTrue("slice param must be less than LR_DIM", sliceMaxCf < LR_DIM);
    assertTrue("slice param must be less than LR_DIM", sliceMaxCq < LR_DIM);
    firstOpts.put(CfCqSliceOpts.OPT_MIN_CF, new String(LONG_LEX.encode(sliceMinCf), UTF_8));
    firstOpts.put(CfCqSliceOpts.OPT_MAX_CF, new String(LONG_LEX.encode(sliceMaxCf), UTF_8));
    secondOpts.put(CfCqSliceOpts.OPT_MIN_CQ, new String(LONG_LEX.encode(sliceMinCq), UTF_8));
    secondOpts.put(CfCqSliceOpts.OPT_MAX_CQ, new String(LONG_LEX.encode(sliceMaxCq), UTF_8));
    SortedKeyValueIterator<Key, Value> skvi = getFilterClass().newInstance();
    skvi.init(new SortedMapIterator(data), firstOpts, null);
    loadKvs(skvi.deepCopy(null), foundKvs, secondOpts, INFINITY);
    for (int i = 0; i < LR_DIM; i++) {
        for (int j = 0; j < LR_DIM; j++) {
            for (int k = 0; k < LR_DIM; k++) {
                if (j >= sliceMinCf && j <= sliceMaxCf && k >= sliceMinCq && k <= sliceMaxCq) {
                    assertTrue("(r, cf, cq) == (" + i + ", " + j + ", " + k + ") must be found in scan", foundKvs[i][j][k]);
                } else {
                    assertFalse("(r, cf, cq) == (" + i + ", " + j + ", " + k + ") must not be found in scan", foundKvs[i][j][k]);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Value(org.apache.accumulo.core.data.Value) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 45 with SortedMapIterator

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

the class VersioningIteratorTest method test2.

@Test
public void test2() {
    Text colf = new Text("a");
    Text colq = new Text("b");
    TreeMap<Key, Value> tm = new TreeMap<>();
    createTestData(tm, colf, colq);
    try {
        VersioningIterator it = new VersioningIterator();
        IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
        VersioningIterator.setMaxVersions(is, 3);
        it.init(new SortedMapIterator(tm), is.getOptions(), null);
        // after doing this seek, should only get two keys for row 1
        // since we are seeking to the middle of the most recent
        // three keys
        Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 18);
        it.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
        TreeMap<Key, Value> tmOut = iteratorOverTestData(it);
        for (Entry<Key, Value> e : tmOut.entrySet()) {
            assertTrue(e.getValue().get().length == 8);
            assertTrue(16 < encoder.decode(e.getValue().get()));
        }
        assertTrue("size after keeping 2 versions was " + tmOut.size(), tmOut.size() == 2);
    } catch (IOException e) {
        assertFalse(true);
    } catch (Exception e) {
        log.error("{}", e.getMessage(), e);
        assertFalse(true);
    }
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) 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) IOException(java.io.IOException) 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