Search in sources :

Example 11 with SortedMapIterator

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

the class FilterTest method test3.

@Test
public void test3() throws IOException {
    Value dv = new Value();
    TreeMap<Key, Value> tm = new TreeMap<>();
    HashSet<Column> hsc = new HashSet<>();
    hsc.add(new Column("c".getBytes(), null, null));
    Text colf1 = new Text("a");
    Text colq1 = new Text("b");
    Text colf2 = new Text("c");
    Text colq2 = new Text("d");
    Text colf;
    Text colq;
    for (int i = 0; i < 1000; i++) {
        if (Math.abs(Math.ceil(i / 2.0) - i / 2.0) < .001) {
            colf = colf1;
            colq = colq1;
        } else {
            colf = colf2;
            colq = colq2;
        }
        Key k = new Key(new Text(String.format("%03d", i)), colf, colq);
        k.setTimestamp(157l);
        tm.put(k, dv);
    }
    assertEquals(1000, tm.size());
    SortedKeyValueIterator<Key, Value> a = ColumnQualifierFilter.wrap(new SortedMapIterator(tm), hsc);
    a.seek(new Range(), EMPTY_COL_FAMS, false);
    assertEquals(1000, size(a));
    hsc = new HashSet<>();
    hsc.add(new Column("a".getBytes(), "b".getBytes(), null));
    a = ColumnQualifierFilter.wrap(new SortedMapIterator(tm), hsc);
    a.seek(new Range(), EMPTY_COL_FAMS, false);
    int size = size(a);
    assertEquals(500, size);
    hsc = new HashSet<>();
    a = ColumnQualifierFilter.wrap(new SortedMapIterator(tm), hsc);
    a.seek(new Range(), EMPTY_COL_FAMS, false);
    size = size(a);
    assertEquals(1000, size);
}
Also used : Text(org.apache.hadoop.io.Text) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Column(org.apache.accumulo.core.data.Column) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with SortedMapIterator

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

the class FilterTest method test4.

@Test
public void test4() throws IOException {
    Value dv = new Value();
    TreeMap<Key, Value> tm = new TreeMap<>();
    ColumnVisibility le1 = new ColumnVisibility("L1");
    ColumnVisibility le2 = new ColumnVisibility("L0&OFFICIAL");
    ColumnVisibility le3 = new ColumnVisibility("L1&L2");
    ColumnVisibility le4 = new ColumnVisibility("L1&L2&G1");
    ColumnVisibility[] lea = { le1, le2, le3, le4 };
    Authorizations auths = new Authorizations("L1", "L2", "L0", "OFFICIAL");
    for (int i = 0; i < 1000; i++) {
        Key k = new Key(new Text(String.format("%03d", i)), new Text("a"), new Text("b"), new Text(lea[i % 4].getExpression()));
        tm.put(k, dv);
    }
    assertEquals(1000, tm.size());
    SortedKeyValueIterator<Key, Value> a = VisibilityFilter.wrap(new SortedMapIterator(tm), auths, le2.getExpression());
    a.seek(new Range(), EMPTY_COL_FAMS, false);
    int size = size(a);
    assertEquals(750, size);
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) 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 13 with SortedMapIterator

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

the class FilterTest method testDeepCopy.

@Test
public void testDeepCopy() throws IOException {
    Text colf = new Text("a");
    Text colq = new Text("b");
    Value dv = new Value();
    TreeMap<Key, Value> tm = new TreeMap<>();
    for (int i = 0; i < 1000; i++) {
        Key k = new Key(new Text(String.format("%03d", i)), colf, colq);
        tm.put(k, dv);
    }
    assertEquals(1000, tm.size());
    SimpleFilter filter = new SimpleFilter();
    IteratorSetting is = new IteratorSetting(1, SimpleFilter.class);
    Filter.setNegate(is, true);
    filter.init(new SortedMapIterator(tm), is.getOptions(), null);
    SortedKeyValueIterator<Key, Value> copy = filter.deepCopy(null);
    filter.seek(new Range(), EMPTY_COL_FAMS, false);
    int size = size(filter);
    assertEquals(900, size);
    copy.seek(new Range(), EMPTY_COL_FAMS, false);
    size = size(copy);
    assertEquals(900, size);
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) 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 14 with SortedMapIterator

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

the class FilterTest method test2b.

/**
 * Test for fix to ACCUMULO-1604: ColumnAgeOffFilter was throwing an error when using negate Test case for when "negate" is an actual column name
 */
@Test
public void test2b() throws IOException {
    Text colf = new Text("negate");
    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("negate"), 901l);
    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(902, size(a));
    ColumnAgeOffFilter.addTTL(is, new IteratorSetting.Column("negate", "b"), 101l);
    a.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    a.overrideCurrentTime(ts);
    a.seek(new Range(), EMPTY_COL_FAMS, false);
    assertEquals(102, size(a));
    ColumnAgeOffFilter.removeTTL(is, new IteratorSetting.Column("negate", "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(902, 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 15 with SortedMapIterator

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

the class FilterTest method testNoVisFilter.

@Test
public void testNoVisFilter() throws IOException {
    TreeMap<Key, Value> tm = new TreeMap<>();
    Value v = new Value();
    for (int i = 0; i < 1000; i++) {
        Key k = new Key(String.format("%03d", i), "a", "b", i % 10 == 0 ? "vis" : "");
        tm.put(k, v);
    }
    assertEquals(1000, tm.size());
    Filter filter = new ReqVisFilter();
    filter.init(new SortedMapIterator(tm), EMPTY_OPTS, null);
    filter.seek(new Range(), EMPTY_COL_FAMS, false);
    int size = size(filter);
    assertEquals(100, size);
}
Also used : ColumnQualifierFilter(org.apache.accumulo.core.iterators.system.ColumnQualifierFilter) VisibilityFilter(org.apache.accumulo.core.iterators.system.VisibilityFilter) Filter(org.apache.accumulo.core.iterators.Filter) 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)

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