Search in sources :

Example 1 with DefaultIteratorEnvironment

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

the class FilterTest method test2a.

@Test
public void test2a() 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);
    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("a", "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("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(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 2 with DefaultIteratorEnvironment

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

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

the class RegExFilterTest method test1.

@Test
public void test1() throws IOException {
    TreeMap<Key, Value> tm = new TreeMap<>();
    Key k1 = newKeyValue(tm, "boo1", "yup", "20080201", "dog");
    Key k2 = newKeyValue(tm, "boo1", "yap", "20080202", "cat");
    Key k3 = newKeyValue(tm, "boo2", "yip", "20080203", "hamster");
    RegExFilter rei = new RegExFilter();
    rei.describeOptions();
    IteratorSetting is = new IteratorSetting(1, RegExFilter.class);
    RegExFilter.setRegexs(is, ".*2", null, null, null, false);
    assertTrue(rei.validateOptions(is.getOptions()));
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k3));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    // Test substring regex
    is.clearOptions();
    // Should only match hamster
    RegExFilter.setRegexs(is, null, null, null, "amst", false, true);
    rei.validateOptions(is.getOptions());
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k3));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, null, "ya.*", null, null, false);
    assertTrue(rei.validateOptions(is.getOptions()));
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k2));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, null, null, ".*01", null, false);
    assertTrue(rei.validateOptions(is.getOptions()));
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k1));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, null, null, null, ".*at", false);
    assertTrue(rei.validateOptions(is.getOptions()));
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k2));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, null, null, null, ".*ap", false);
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, null, "ya.*", null, ".*at", false);
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k2));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, null, "ya.*", null, ".*ap", false);
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, "boo1", null, null, null, false);
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k2));
    rei.next();
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k1));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k2));
    rei.next();
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k1));
    rei.next();
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k3));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, "hamster", null, "hamster", "hamster", true);
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k3));
    rei.next();
    assertFalse(rei.hasTop());
    // -----------------------------------------------------
    is.clearOptions();
    RegExFilter.setRegexs(is, null, "ya.*", "hamster", null, true);
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    assertTrue(rei.getTopKey().equals(k2));
    rei.next();
    assertFalse(rei.hasTop());
    is.clearOptions();
    RegExFilter.setRegexs(is, null, "ya.*", "hamster", null, true);
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    rei.deepCopy(new DefaultIteratorEnvironment());
    // -----------------------------------------------------
    String multiByteText = new String("\u6d67" + "\u6F68" + "\u7067");
    String multiByteRegex = new String(".*" + "\u6F68" + ".*");
    Key k4 = new Key("boo4".getBytes(), "hoo".getBytes(), "20080203".getBytes(), "".getBytes(), 1l);
    Value inVal = new Value(multiByteText.getBytes(UTF_8));
    tm.put(k4, inVal);
    is.clearOptions();
    RegExFilter.setRegexs(is, null, null, null, multiByteRegex, true);
    rei.init(new SortedMapIterator(tm), is.getOptions(), new DefaultIteratorEnvironment());
    rei.seek(new Range(), EMPTY_COL_FAMS, false);
    assertTrue(rei.hasTop());
    Value outValue = rei.getTopValue();
    String outVal = new String(outValue.get(), UTF_8);
    assertTrue(outVal.equals(multiByteText));
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) DefaultIteratorEnvironment(org.apache.accumulo.core.iterators.DefaultIteratorEnvironment) 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 4 with DefaultIteratorEnvironment

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

the class ColumnSliceFilterTest method setUp.

@Before
public void setUp() throws Exception {
    columnSliceFilter.describeOptions();
    iteratorEnvironment = new DefaultIteratorEnvironment();
    is = new IteratorSetting(1, ColumnSliceFilter.class);
}
Also used : DefaultIteratorEnvironment(org.apache.accumulo.core.iterators.DefaultIteratorEnvironment) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Before(org.junit.Before)

Example 5 with DefaultIteratorEnvironment

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

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