Search in sources :

Example 6 with DefaultIteratorEnvironment

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

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

the class FilterTest method test2aNegate.

/**
 * Test for fix to ACCUMULO-1604: ColumnAgeOffFilter was throwing an error when using negate
 */
@Test
public void test2aNegate() throws IOException {
    Text colf = new Text("a");
    Text colq = new Text("b");
    Value dv = new Value();
    TreeMap<Key, Value> tm = new TreeMap<>();
    IteratorSetting is = new IteratorSetting(1, ColumnAgeOffFilter.class);
    ColumnAgeOffFilter.addTTL(is, new IteratorSetting.Column("a"), 901l);
    ColumnAgeOffFilter.setNegate(is, true);
    long ts = System.currentTimeMillis();
    for (long i = 0; i < 1000; i++) {
        Key k = new Key(new Text(String.format("%03d", i)), colf, colq, ts - i);
        tm.put(k, dv);
    }
    assertEquals(1000, tm.size());
    ColumnAgeOffFilter a = new ColumnAgeOffFilter();
    assertTrue(a.validateOptions(is.getOptions()));
    a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    a.overrideCurrentTime(ts);
    a.seek(new Range(), EMPTY_COL_FAMS, false);
    assertEquals(98, size(a));
    ColumnAgeOffFilter.addTTL(is, new IteratorSetting.Column("a", "b"), 101l);
    a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    a.overrideCurrentTime(ts);
    a.seek(new Range(), EMPTY_COL_FAMS, false);
    assertEquals(898, size(a));
    ColumnAgeOffFilter.removeTTL(is, new IteratorSetting.Column("a", "b"));
    a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    a = (ColumnAgeOffFilter) a.deepCopy(null);
    a.overrideCurrentTime(ts);
    a.seek(new Range(), EMPTY_COL_FAMS, false);
    assertEquals(98, size(a));
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) DefaultIteratorEnvironment(org.apache.accumulo.core.iterators.DefaultIteratorEnvironment) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) 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 8 with DefaultIteratorEnvironment

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

Example 9 with DefaultIteratorEnvironment

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

the class RowFilterTest method testFilterConjunction.

@Test
public void testFilterConjunction() throws Exception {
    SortedMapIterator source = new SortedMapIterator(createKeyValues());
    RowFilter filter0 = new RowZeroOrOneFilter();
    filter0.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
    RowFilter filter = new RowOneOrTwoFilter();
    filter.init(filter0, Collections.emptyMap(), new DefaultIteratorEnvironment());
    filter.seek(new Range(), Collections.emptySet(), false);
    assertEquals(new HashSet<>(Arrays.asList("1")), 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)

Aggregations

DefaultIteratorEnvironment (org.apache.accumulo.core.iterators.DefaultIteratorEnvironment)9 Range (org.apache.accumulo.core.data.Range)8 SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)8 Test (org.junit.Test)8 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)5 Key (org.apache.accumulo.core.data.Key)5 Value (org.apache.accumulo.core.data.Value)5 TreeMap (java.util.TreeMap)4 Text (org.apache.hadoop.io.Text)3 ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)1 ByteSequence (org.apache.accumulo.core.data.ByteSequence)1 ColumnFamilySkippingIterator (org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator)1 Before (org.junit.Before)1