This is an automated email from the ASF dual-hosted git repository.
domgarguilo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new c944d229f7 Consolidate iterator parsing code (#6111)
c944d229f7 is described below
commit c944d229f7605175b78841be6a6b65dbdff244b4
Author: Dom G. <[email protected]>
AuthorDate: Thu Feb 12 09:47:07 2026 -0500
Consolidate iterator parsing code (#6111)
* Consolidate iterator parsing code
---------
Co-authored-by: Keith Turner <[email protected]>
---
.../core/clientImpl/NamespaceOperationsHelper.java | 54 ++++++++++-----------
.../core/clientImpl/TableOperationsHelper.java | 56 ++++++++++------------
.../core/iteratorsImpl/IteratorProperty.java | 21 ++++----
3 files changed, 62 insertions(+), 69 deletions(-)
diff --git
a/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java
b/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java
index f27d28cfc1..f756e6392b 100644
---
a/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java
+++
b/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java
@@ -33,6 +33,7 @@ import
org.apache.accumulo.core.client.admin.NamespaceOperations;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.iteratorsImpl.IteratorConfigUtil;
+import org.apache.accumulo.core.iteratorsImpl.IteratorProperty;
public abstract class NamespaceOperationsHelper implements NamespaceOperations
{
@@ -92,29 +93,26 @@ public abstract class NamespaceOperationsHelper implements
NamespaceOperations {
if (!exists(namespace)) {
throw new NamespaceNotFoundException(null, namespace, null);
}
- int priority = -1;
- String classname = null;
- Map<String,String> settings = new HashMap<>();
-
- String root =
- String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX,
scope.name().toLowerCase(), name);
- String opt = root + ".opt.";
- for (Entry<String,String> property : this.getProperties(namespace)) {
- if (property.getKey().equals(root)) {
- String[] parts = property.getValue().split(",");
- if (parts.length != 2) {
- throw new AccumuloException("Bad value for iterator setting: " +
property.getValue());
- }
- priority = Integer.parseInt(parts[0]);
- classname = parts[1];
- } else if (property.getKey().startsWith(opt)) {
- settings.put(property.getKey().substring(opt.length()),
property.getValue());
+ Map<String,String> properties =
Map.copyOf(this.getConfiguration(namespace));
+ IteratorProperty base = null;
+ Map<String,String> options = new HashMap<>();
+ for (Entry<String,String> entry : properties.entrySet()) {
+ IteratorProperty iterProp = IteratorProperty.parse(entry);
+ if (iterProp == null || iterProp.getScope() != scope ||
!iterProp.getName().equals(name)) {
+ continue;
+ }
+ if (iterProp.isOption()) {
+ options.put(iterProp.getOptionKey(), iterProp.getOptionValue());
+ } else {
+ base = iterProp;
}
}
- if (priority <= 0 || classname == null) {
+ if (base == null) {
return null;
}
- return new IteratorSetting(priority, name, classname, settings);
+ IteratorSetting setting = base.toSetting();
+ options.forEach(setting::addOption);
+ return setting;
}
@Override
@@ -124,18 +122,14 @@ public abstract class NamespaceOperationsHelper
implements NamespaceOperations {
throw new NamespaceNotFoundException(null, namespace, null);
}
Map<String,EnumSet<IteratorScope>> result = new TreeMap<>();
- for (Entry<String,String> property : this.getProperties(namespace)) {
- 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);
- }
+ Map<String,String> properties =
Map.copyOf(this.getConfiguration(namespace));
+ for (Entry<String,String> entry : properties.entrySet()) {
+ IteratorProperty iterProp = IteratorProperty.parse(entry);
+ if (iterProp == null || iterProp.isOption()) {
+ continue;
}
+ result.computeIfAbsent(iterProp.getName(), k ->
EnumSet.noneOf(IteratorScope.class))
+ .add(iterProp.getScope());
}
return result;
}
diff --git
a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java
b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java
index 03be6dcb1c..1107f0b2fa 100644
---
a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java
+++
b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java
@@ -36,6 +36,7 @@ import org.apache.accumulo.core.client.admin.TableOperations;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.iteratorsImpl.IteratorConfigUtil;
+import org.apache.accumulo.core.iteratorsImpl.IteratorProperty;
public abstract class TableOperationsHelper implements TableOperations {
@@ -84,34 +85,31 @@ public abstract class TableOperationsHelper implements
TableOperations {
@Override
public IteratorSetting getIteratorSetting(String tableName, String name,
IteratorScope scope)
- throws AccumuloSecurityException, AccumuloException,
TableNotFoundException {
+ throws AccumuloException, TableNotFoundException {
EXISTING_TABLE_NAME.validate(tableName);
checkArgument(name != null, "name is null");
checkArgument(scope != null, "scope is null");
- int priority = -1;
- String classname = null;
- Map<String,String> settings = new HashMap<>();
-
- String root =
- String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX,
scope.name().toLowerCase(), name);
- String opt = root + ".opt.";
- for (Entry<String,String> property : this.getProperties(tableName)) {
- if (property.getKey().equals(root)) {
- String[] parts = property.getValue().split(",");
- if (parts.length != 2) {
- throw new AccumuloException("Bad value for iterator setting: " +
property.getValue());
- }
- priority = Integer.parseInt(parts[0]);
- classname = parts[1];
- } else if (property.getKey().startsWith(opt)) {
- settings.put(property.getKey().substring(opt.length()),
property.getValue());
+ Map<String,String> properties =
Map.copyOf(this.getConfiguration(tableName));
+ IteratorProperty base = null;
+ Map<String,String> options = new HashMap<>();
+ for (Entry<String,String> entry : properties.entrySet()) {
+ IteratorProperty iterProp = IteratorProperty.parse(entry);
+ if (iterProp == null || iterProp.getScope() != scope ||
!iterProp.getName().equals(name)) {
+ continue;
+ }
+ if (iterProp.isOption()) {
+ options.put(iterProp.getOptionKey(), iterProp.getOptionValue());
+ } else {
+ base = iterProp;
}
}
- if (priority <= 0 || classname == null) {
+ if (base == null) {
return null;
}
- return new IteratorSetting(priority, name, classname, settings);
+ IteratorSetting setting = base.toSetting();
+ options.forEach(setting::addOption);
+ return setting;
}
@Override
@@ -120,18 +118,14 @@ public abstract class TableOperationsHelper implements
TableOperations {
EXISTING_TABLE_NAME.validate(tableName);
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);
- }
+ Map<String,String> properties =
Map.copyOf(this.getConfiguration(tableName));
+ for (Entry<String,String> entry : properties.entrySet()) {
+ IteratorProperty iterProp = IteratorProperty.parse(entry);
+ if (iterProp == null || iterProp.isOption()) {
+ continue;
}
+ result.computeIfAbsent(iterProp.getName(), k ->
EnumSet.noneOf(IteratorScope.class))
+ .add(iterProp.getScope());
}
return result;
}
diff --git
a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java
b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java
index 20120b4b6c..88ffdcd817 100644
---
a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java
+++
b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java
@@ -113,9 +113,7 @@ public class IteratorProperty {
}
private static void check(boolean b, String property, String value) {
- if (!b) {
- throw new IllegalArgumentException("Illegal iterator property: " +
property + "=" + value);
- }
+ Preconditions.checkArgument(b, "Illegal iterator property: %s=%s",
property, value);
}
@Override
@@ -140,19 +138,26 @@ public class IteratorProperty {
return null;
}
- String[] iterPropParts = property.split("\\.");
+ String[] iterPropParts = property.split("\\.", -1);
check(iterPropParts.length == 4 || iterPropParts.length == 6, property,
value);
IteratorUtil.IteratorScope scope =
IteratorUtil.IteratorScope.valueOf(iterPropParts[2]);
String iterName = iterPropParts[3];
+ check(!iterName.isEmpty(), property, value);
if (iterPropParts.length == 4) {
- String[] valTokens = value.split(",");
+ String[] valTokens = value.split(",", -1);
check(valTokens.length == 2, property, value);
- return new IteratorProperty(iterName, scope,
Integer.parseInt(valTokens[0]), valTokens[1],
- property, value);
+ String prioStr = valTokens[0];
+ String className = valTokens[1];
+ check(!className.isEmpty(), property, value);
+ int priority = Integer.parseInt(prioStr);
+ check(priority > 0, property, value);
+ return new IteratorProperty(iterName, scope, priority, className,
property, value);
} else if (iterPropParts.length == 6) {
check(iterPropParts[4].equals("opt"), property, value);
- return new IteratorProperty(iterName, scope, iterPropParts[5], value,
property, value);
+ String optionName = iterPropParts[5];
+ check(!optionName.isEmpty(), property, value);
+ return new IteratorProperty(iterName, scope, optionName, value,
property, value);
} else {
throw new IllegalArgumentException("Illegal iterator property: " +
property + "=" + value);
}