use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project geowave by locationtech.
the class AccumuloOperations method attachIterators.
public boolean attachIterators(final String tableName, final boolean createTable, final boolean enableVersioning, final boolean enableBlockCache, final IteratorConfig... iterators) throws TableNotFoundException {
final String qName = getQualifiedTableName(tableName);
if (createTable && !getConnector().tableOperations().exists(qName)) {
createTable(tableName, enableVersioning, enableBlockCache);
}
try {
if ((iterators != null) && (iterators.length > 0)) {
final Map<String, EnumSet<IteratorScope>> iteratorScopes = getConnector().tableOperations().listIterators(qName);
for (final IteratorConfig iteratorConfig : iterators) {
boolean mustDelete = false;
boolean exists = false;
final EnumSet<IteratorScope> existingScopes = iteratorScopes.get(iteratorConfig.getIteratorName());
EnumSet<IteratorScope> configuredScopes;
if (iteratorConfig.getScopes() == null) {
configuredScopes = EnumSet.allOf(IteratorScope.class);
} else {
configuredScopes = iteratorConfig.getScopes();
}
Map<String, String> configuredOptions = null;
if (existingScopes != null) {
if (existingScopes.size() == configuredScopes.size()) {
exists = true;
for (final IteratorScope s : existingScopes) {
if (!configuredScopes.contains(s)) {
// this iterator exists with the wrong
// scope, we will assume we want to remove
// it and add the new configuration
LOGGER.warn("found iterator '" + iteratorConfig.getIteratorName() + "' missing scope '" + s.name() + "', removing it and re-attaching");
mustDelete = true;
break;
}
}
}
if (existingScopes.size() > 0) {
// see if the options are the same, if they are not
// the same, apply a merge with the existing options
// and the configured options
final Iterator<IteratorScope> it = existingScopes.iterator();
while (it.hasNext()) {
final IteratorScope scope = it.next();
final IteratorSetting setting = getConnector().tableOperations().getIteratorSetting(qName, iteratorConfig.getIteratorName(), scope);
if (setting != null) {
final Map<String, String> existingOptions = setting.getOptions();
configuredOptions = iteratorConfig.getOptions(existingOptions);
if (existingOptions == null) {
mustDelete = (configuredOptions == null);
} else if (configuredOptions == null) {
mustDelete = true;
} else {
// neither are null, compare the size of
// the entry sets and check that they
// are equivalent
final Set<Entry<String, String>> existingEntries = existingOptions.entrySet();
final Set<Entry<String, String>> configuredEntries = configuredOptions.entrySet();
if (existingEntries.size() != configuredEntries.size()) {
mustDelete = true;
} else {
mustDelete = (!existingEntries.containsAll(configuredEntries));
}
}
// for each scope
break;
}
}
}
}
if (mustDelete) {
getConnector().tableOperations().removeIterator(qName, iteratorConfig.getIteratorName(), existingScopes);
exists = false;
}
if (!exists) {
if (configuredOptions == null) {
configuredOptions = iteratorConfig.getOptions(new HashMap<>());
}
getConnector().tableOperations().attachIterator(qName, new IteratorSetting(iteratorConfig.getIteratorPriority(), iteratorConfig.getIteratorName(), iteratorConfig.getIteratorClass(), configuredOptions), configuredScopes);
}
}
}
} catch (AccumuloException | AccumuloSecurityException e) {
LOGGER.warn("Unable to create table '" + qName + "'", e);
}
return true;
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class TableOperationsHelperTest method testAttachIterator.
@Test
public void testAttachIterator() throws Exception {
TableOperationsHelper t = getHelper();
Map<String, String> empty = Collections.emptyMap();
t.attachIterator("table", new IteratorSetting(10, "someName", "foo.bar", empty), EnumSet.of(IteratorScope.scan));
check(t, "table", new String[] { "table.iterator.scan.someName=10,foo.bar" });
t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan));
check(t, "table", new String[] {});
IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
setting.addOptions(Collections.singletonMap("key", "value"));
t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc));
setting = new IteratorSetting(10, "someName", "foo.bar");
t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan));
check(t, "table", new String[] { "table.iterator.majc.someName=10,foo.bar", "table.iterator.majc.someName.opt.key=value", "table.iterator.scan.someName=10,foo.bar" });
t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan));
setting = new IteratorSetting(20, "otherName", "some.classname");
setting.addOptions(Collections.singletonMap("key", "value"));
t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc));
setting = new IteratorSetting(20, "otherName", "some.classname");
t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan));
Map<String, EnumSet<IteratorScope>> two = t.listIterators("table");
Assert.assertEquals(2, two.size());
Assert.assertTrue(two.containsKey("otherName"));
Assert.assertTrue(two.get("otherName").size() == 2);
Assert.assertTrue(two.get("otherName").contains(IteratorScope.majc));
Assert.assertTrue(two.get("otherName").contains(IteratorScope.scan));
Assert.assertTrue(two.containsKey("someName"));
Assert.assertTrue(two.get("someName").size() == 1);
Assert.assertTrue(two.get("someName").contains(IteratorScope.majc));
t.removeIterator("table", "someName", EnumSet.allOf(IteratorScope.class));
check(t, "table", new String[] { "table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value", "table.iterator.scan.otherName=20,some.classname" });
setting = t.getIteratorSetting("table", "otherName", IteratorScope.scan);
Assert.assertEquals(20, setting.getPriority());
Assert.assertEquals("some.classname", setting.getIteratorClass());
Assert.assertTrue(setting.getOptions().isEmpty());
setting = t.getIteratorSetting("table", "otherName", IteratorScope.majc);
Assert.assertEquals(20, setting.getPriority());
Assert.assertEquals("some.classname", setting.getIteratorClass());
Assert.assertFalse(setting.getOptions().isEmpty());
Assert.assertEquals(Collections.singletonMap("key", "value"), setting.getOptions());
t.attachIterator("table", setting, EnumSet.of(IteratorScope.minc));
check(t, "table", new String[] { "table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value", "table.iterator.minc.otherName=20,some.classname", "table.iterator.minc.otherName.opt.key=value", "table.iterator.scan.otherName=20,some.classname" });
try {
t.attachIterator("table", setting);
Assert.fail();
} catch (AccumuloException e) {
// expected, ignore
}
setting.setName("thirdName");
try {
t.attachIterator("table", setting);
Assert.fail();
} catch (AccumuloException e) {
}
setting.setPriority(10);
t.setProperty("table", "table.iterator.minc.thirdName.opt.key", "value");
try {
t.attachIterator("table", setting);
Assert.fail();
} catch (AccumuloException e) {
}
t.removeProperty("table", "table.iterator.minc.thirdName.opt.key");
t.attachIterator("table", setting);
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class TableOperationsHelper method listIterators.
@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
Map<String, EnumSet<IteratorScope>> result = new TreeMap<>();
for (Entry<String, String> property : this.getProperties(tableName)) {
String name = property.getKey();
String[] parts = name.split("\\.");
if (parts.length == 4) {
if (parts[0].equals("table") && parts[1].equals("iterator")) {
IteratorScope scope = IteratorScope.valueOf(parts[2]);
if (!result.containsKey(parts[3]))
result.put(parts[3], EnumSet.noneOf(IteratorScope.class));
result.get(parts[3]).add(scope);
}
}
}
return result;
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class NamespaceOperationsHelper method attachIterator.
@Override
public void attachIterator(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
checkIteratorConflicts(namespace, setting, scopes);
for (IteratorScope scope : scopes) {
String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), setting.getName());
for (Entry<String, String> prop : setting.getOptions().entrySet()) {
this.setProperty(namespace, root + ".opt." + prop.getKey(), prop.getValue());
}
this.setProperty(namespace, root, setting.getPriority() + "," + setting.getIteratorClass());
}
}
use of org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope in project accumulo by apache.
the class SummingCombinerTest method getIteratorInput.
private static IteratorTestInput getIteratorInput() {
IteratorSetting setting = new IteratorSetting(50, SummingCombiner.class);
LongCombiner.setEncodingType(setting, LongCombiner.Type.STRING);
Combiner.setCombineAllColumns(setting, true);
Combiner.setReduceOnFullCompactionOnly(setting, false);
return new IteratorTestInput(SummingCombiner.class, setting.getOptions(), new Range(), INPUT_DATA, new SimpleIteratorEnvironment() {
@Override
public IteratorScope getIteratorScope() {
return IteratorScope.majc;
}
});
}
Aggregations