Search in sources :

Example 1 with IteratorEnvironment

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

the class CombinerTest method testDeleteHandling.

@Test
public void testDeleteHandling() throws Exception {
    Encoder<Long> encoder = LongCombiner.STRING_ENCODER;
    TreeMap<Key, Value> input = new TreeMap<>();
    IteratorEnvironment paritalMajcIe = new CombinerIteratorEnvironment(IteratorScope.majc, false);
    IteratorEnvironment fullMajcIe = new CombinerIteratorEnvironment(IteratorScope.majc, true);
    // keys that aggregate
    newKeyValue(input, 1, 1, 1, 1, false, 4l, encoder);
    newKeyValue(input, 1, 1, 1, 2, true, 0l, encoder);
    newKeyValue(input, 1, 1, 1, 3, false, 2l, encoder);
    newKeyValue(input, 1, 1, 1, 4, false, 9l, encoder);
    TreeMap<Key, Value> expected = new TreeMap<>();
    newKeyValue(expected, 1, 1, 1, 1, false, 4l, encoder);
    newKeyValue(expected, 1, 1, 1, 2, true, 0l, encoder);
    newKeyValue(expected, 1, 1, 1, 4, false, 11l, encoder);
    runDeleteHandlingTest(input, input, true, paritalMajcIe);
    runDeleteHandlingTest(input, expected, true, fullMajcIe);
    runDeleteHandlingTest(input, expected, true, SCAN_IE);
    runDeleteHandlingTest(input, expected, false, fullMajcIe, ".*ERROR.*ACCUMULO-2232.*");
    runDeleteHandlingTest(input, expected, false, SCAN_IE);
    runDeleteHandlingTest(input, expected, false, paritalMajcIe, ".*ERROR.*SummingCombiner.*ACCUMULO-2232.*");
    runDeleteHandlingTest(input, expected, null, paritalMajcIe, ".*ERROR.*SummingCombiner.*ACCUMULO-2232.*");
    runDeleteHandlingTest(input, expected, null, fullMajcIe, ".*ERROR.*SummingCombiner.*ACCUMULO-2232.*");
}
Also used : DefaultIteratorEnvironment(org.apache.accumulo.core.iterators.DefaultIteratorEnvironment) IteratorEnvironment(org.apache.accumulo.core.iterators.IteratorEnvironment) Value(org.apache.accumulo.core.data.Value) TreeMap(java.util.TreeMap) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 2 with IteratorEnvironment

use of org.apache.accumulo.core.iterators.IteratorEnvironment in project accumulo-examples by apache.

the class CutoffIntersectingIterator method init.

@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    IteratorEnvironment sampleEnv = env.cloneWithSamplingEnabled();
    setMax(sampleEnv, options);
    SortedKeyValueIterator<Key, Value> sampleDC = source.deepCopy(sampleEnv);
    sampleII = new IntersectingIterator();
    sampleII.init(sampleDC, options, env);
}
Also used : IteratorEnvironment(org.apache.accumulo.core.iterators.IteratorEnvironment) IntersectingIterator(org.apache.accumulo.core.iterators.user.IntersectingIterator) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 3 with IteratorEnvironment

use of org.apache.accumulo.core.iterators.IteratorEnvironment in project Gaffer by gchq.

the class RFileReaderIterator method applyIterator.

private SortedKeyValueIterator<Key, Value> applyIterator(final SortedKeyValueIterator<Key, Value> source, final IteratorSetting is) {
    try {
        SortedKeyValueIterator<Key, Value> result = Class.forName(is.getIteratorClass()).asSubclass(SortedKeyValueIterator.class).newInstance();
        result.init(source, is.getOptions(), new IteratorEnvironment() {

            @Override
            public SortedKeyValueIterator<Key, Value> reserveMapFileReader(final String mapFileName) {
                return null;
            }

            @Override
            public AccumuloConfiguration getConfig() {
                return null;
            }

            @Override
            public IteratorUtil.IteratorScope getIteratorScope() {
                return IteratorUtil.IteratorScope.majc;
            }

            @Override
            public boolean isFullMajorCompaction() {
                return false;
            }

            @Override
            public void registerSideChannel(final SortedKeyValueIterator<Key, Value> iter) {
            }

            @Override
            public Authorizations getAuthorizations() {
                return null;
            }

            @Override
            public IteratorEnvironment cloneWithSamplingEnabled() {
                return null;
            }

            @Override
            public boolean isSamplingEnabled() {
                return false;
            }

            @Override
            public SamplerConfiguration getSamplerConfiguration() {
                return null;
            }
        });
        return result;
    } catch (final IOException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new RuntimeException("Exception creating iterator of class " + is.getIteratorClass());
    }
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) IteratorEnvironment(org.apache.accumulo.core.iterators.IteratorEnvironment) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) IOException(java.io.IOException) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 4 with IteratorEnvironment

use of org.apache.accumulo.core.iterators.IteratorEnvironment in project Gaffer by gchq.

the class AggregatorIteratorTest method shouldGetGroupFromElementConverter.

@Test
public void shouldGetGroupFromElementConverter() throws IOException {
    MockAccumuloElementConverter.cleanUp();
    // Given
    MockAccumuloElementConverter.mock = mock(AccumuloElementConverter.class);
    final Key key = mock(Key.class);
    final List<Value> values = Arrays.asList(mock(Value.class), mock(Value.class));
    final Schema schema = new Schema.Builder().edge(TestGroups.ENTITY, new SchemaEdgeDefinition()).build();
    final ByteSequence colFamData = mock(ByteSequence.class);
    final byte[] colFam = StringUtil.toBytes(TestGroups.ENTITY);
    final SortedKeyValueIterator sortedKeyValueIterator = mock(SortedKeyValueIterator.class);
    final IteratorEnvironment iteratorEnvironment = mock(IteratorEnvironment.class);
    final Map<String, String> options = new HashMap();
    options.put("columns", "test");
    options.put(AccumuloStoreConstants.SCHEMA, new String(schema.toCompactJson()));
    options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, MockAccumuloElementConverter.class.getName());
    given(colFamData.getBackingArray()).willReturn(colFam);
    given(key.getColumnFamilyData()).willReturn(colFamData);
    given(MockAccumuloElementConverter.mock.getGroupFromColumnFamily(colFam)).willReturn(TestGroups.ENTITY);
    final AggregatorIterator aggregatorIterator = new AggregatorIterator();
    // When
    aggregatorIterator.init(sortedKeyValueIterator, options, iteratorEnvironment);
    aggregatorIterator.reduce(key, values.iterator());
    // Then
    verify(MockAccumuloElementConverter.mock, times(1)).getGroupFromColumnFamily(colFam);
    MockAccumuloElementConverter.cleanUp();
}
Also used : HashMap(java.util.HashMap) Schema(uk.gov.gchq.gaffer.store.schema.Schema) IteratorEnvironment(org.apache.accumulo.core.iterators.IteratorEnvironment) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) AccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter) MockAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.MockAccumuloElementConverter) Value(org.apache.accumulo.core.data.Value) MockAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.MockAccumuloElementConverter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) Test(org.junit.jupiter.api.Test)

Example 5 with IteratorEnvironment

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

the class TransformingIteratorTest method setUpTransformIterator.

private void setUpTransformIterator(Class<? extends TransformingIterator> clazz, boolean setupAuths) throws IOException {
    SortedMapIterator source = new SortedMapIterator(data);
    ColumnFamilySkippingIterator cfsi = new ColumnFamilySkippingIterator(source);
    SortedKeyValueIterator<Key, Value> visFilter = VisibilityFilter.wrap(cfsi, authorizations, new byte[0]);
    ReuseIterator reuserIter = new ReuseIterator();
    reuserIter.init(visFilter, EMPTY_OPTS, null);
    try {
        titer = clazz.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    IteratorEnvironment iterEnv = EasyMock.createMock(IteratorEnvironment.class);
    EasyMock.expect(iterEnv.getIteratorScope()).andReturn(IteratorScope.scan).anyTimes();
    EasyMock.replay(iterEnv);
    Map<String, String> opts;
    if (setupAuths) {
        IteratorSetting cfg = new IteratorSetting(21, clazz);
        TransformingIterator.setAuthorizations(cfg, new Authorizations("vis0", "vis1", "vis2", "vis3"));
        opts = cfg.getOptions();
    } else {
        opts = ImmutableMap.of();
    }
    titer.init(reuserIter, opts, iterEnv);
}
Also used : ColumnFamilySkippingIterator(org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator) Authorizations(org.apache.accumulo.core.security.Authorizations) BaseIteratorEnvironment(org.apache.accumulo.core.client.impl.BaseIteratorEnvironment) IteratorEnvironment(org.apache.accumulo.core.iterators.IteratorEnvironment) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

Key (org.apache.accumulo.core.data.Key)5 Value (org.apache.accumulo.core.data.Value)5 IteratorEnvironment (org.apache.accumulo.core.iterators.IteratorEnvironment)5 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)2 Authorizations (org.apache.accumulo.core.security.Authorizations)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 BaseIteratorEnvironment (org.apache.accumulo.core.client.impl.BaseIteratorEnvironment)1 SamplerConfiguration (org.apache.accumulo.core.client.sample.SamplerConfiguration)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 ByteSequence (org.apache.accumulo.core.data.ByteSequence)1 PartialKey (org.apache.accumulo.core.data.PartialKey)1 DefaultIteratorEnvironment (org.apache.accumulo.core.iterators.DefaultIteratorEnvironment)1 SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)1 ColumnFamilySkippingIterator (org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator)1 IntersectingIterator (org.apache.accumulo.core.iterators.user.IntersectingIterator)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1