This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new bdb8ce9725 Add fine-grained options to GrepIterator
bdb8ce9725 is described below
commit bdb8ce9725e007435db55b438f577065fafb1151
Author: Christopher Tubbs <[email protected]>
AuthorDate: Mon Jul 29 01:14:17 2024 -0400
Add fine-grained options to GrepIterator
Update the previously merged feature to match on column visibilities
using the GrepIterator, which was added in PR #4468
Now, GrepIterator supports a number of fine-grained options to choose
exactly which fields to match on. It preserves the behavior prior to the
changes in PR #4468 by default for the GrepIterator, but retains the
change to the GrepCommand for the shell by enabling the new option to
match on column visibilities.
---
.../accumulo/core/iterators/user/GrepIterator.java | 80 ++++++++++++++++++++--
.../core/iterators/user/GrepIteratorTest.java | 1 +
.../accumulo/shell/commands/GrepCommand.java | 6 +-
3 files changed, 79 insertions(+), 8 deletions(-)
diff --git
a/core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java
b/core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java
index 9e3fa110c8..ed327f70d1 100644
---
a/core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java
+++
b/core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java
@@ -33,18 +33,45 @@ import
org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
/**
- * This iterator provides exact string matching. It searches both the Key and
Value for the string.
- * The string to match is specified by the "term" option.
+ * This iterator provides exact string matching of the term specified by the
"term" option. It
+ * searches both the Key and Value for the string, according to the specified
configuration options.
+ *
+ * <p>
+ * The match options are:
+ * <ul>
+ * <li>term (String, required)
+ * <li>matchRow (boolean, default: true)
+ * <li>matchColumnFamily (boolean, default: true)
+ * <li>matchColumnQualifier (boolean, default: true)
+ * <li>matchColumnVisibility (boolean, default: false)
+ * <li>matchValue (boolean, default: true)
+ * </ul>
*/
public class GrepIterator extends Filter {
+ private static final String TERM_OPT = "term";
+
+ private static final String MATCH_ROW_OPT = "matchRow";
+ private static final String MATCH_COLFAM_OPT = "matchColumnFamily";
+ private static final String MATCH_COLQUAL_OPT = "matchColumnQualifier";
+ private static final String MATCH_COLVIS_OPT = "matchColumnVisibility";
+ private static final String MATCH_VALUE_OPT = "matchValue";
+
private byte[] term;
private int[] right = new int[256];
+ private boolean matchRow = true;
+ private boolean matchColFam = true;
+ private boolean matchColQual = true;
+ private boolean matchColVis = false;
+ private boolean matchValue = true;
+
@Override
public boolean accept(Key k, Value v) {
- return match(v.get()) || match(k.getRowData()) ||
match(k.getColumnFamilyData())
- || match(k.getColumnQualifierData()) ||
match(k.getColumnVisibilityData());
+ return (matchValue && match(v.get())) || (matchRow &&
match(k.getRowData()))
+ || (matchColFam && match(k.getColumnFamilyData()))
+ || (matchColQual && match(k.getColumnQualifierData()))
+ || (matchColVis && match(k.getColumnVisibilityData()));
}
protected boolean match(ByteSequence bs) {
@@ -77,6 +104,11 @@ public class GrepIterator extends Filter {
public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) {
GrepIterator copy = (GrepIterator) super.deepCopy(env);
copy.term = Arrays.copyOf(term, term.length);
+ copy.matchRow = matchRow;
+ copy.matchColFam = matchColFam;
+ copy.matchColQual = matchColQual;
+ copy.matchColVis = matchColVis;
+ copy.matchValue = matchValue;
return copy;
}
@@ -84,19 +116,55 @@ public class GrepIterator extends Filter {
public void init(SortedKeyValueIterator<Key,Value> source,
Map<String,String> options,
IteratorEnvironment env) throws IOException {
super.init(source, options, env);
- term = options.get("term").getBytes(UTF_8);
+ term = options.get(TERM_OPT).getBytes(UTF_8);
for (int i = 0; i < right.length; i++) {
right[i] = -1;
}
for (int i = 0; i < term.length; i++) {
right[term[i] & 0xff] = i;
}
+ String matchItem = null;
+ if ((matchItem = options.get(MATCH_ROW_OPT)) != null) {
+ matchRow = Boolean.parseBoolean(matchItem);
+ }
+ if ((matchItem = options.get(MATCH_COLFAM_OPT)) != null) {
+ matchColFam = Boolean.parseBoolean(matchItem);
+ }
+ if ((matchItem = options.get(MATCH_COLQUAL_OPT)) != null) {
+ matchColQual = Boolean.parseBoolean(matchItem);
+ }
+ if ((matchItem = options.get(MATCH_COLVIS_OPT)) != null) {
+ matchColVis = Boolean.parseBoolean(matchItem);
+ }
+ if ((matchItem = options.get(MATCH_VALUE_OPT)) != null) {
+ matchValue = Boolean.parseBoolean(matchItem);
+ }
}
/**
* Encode the grep term as an option for a ScanIterator
*/
public static void setTerm(IteratorSetting cfg, String term) {
- cfg.addOption("term", term);
+ cfg.addOption(TERM_OPT, term);
+ }
+
+ public static void matchRow(IteratorSetting cfg, boolean match) {
+ cfg.addOption(MATCH_ROW_OPT, Boolean.toString(match));
+ }
+
+ public static void matchColumnFamily(IteratorSetting cfg, boolean match) {
+ cfg.addOption(MATCH_COLFAM_OPT, Boolean.toString(match));
+ }
+
+ public static void matchColumnQualifier(IteratorSetting cfg, boolean match) {
+ cfg.addOption(MATCH_COLQUAL_OPT, Boolean.toString(match));
+ }
+
+ public static void matchColumnVisibility(IteratorSetting cfg, boolean match)
{
+ cfg.addOption(MATCH_COLVIS_OPT, Boolean.toString(match));
+ }
+
+ public static void matchValue(IteratorSetting cfg, boolean match) {
+ cfg.addOption(MATCH_VALUE_OPT, Boolean.toString(match));
}
}
diff --git
a/core/src/test/java/org/apache/accumulo/core/iterators/user/GrepIteratorTest.java
b/core/src/test/java/org/apache/accumulo/core/iterators/user/GrepIteratorTest.java
index e1c0e30fbd..191a0403a0 100644
---
a/core/src/test/java/org/apache/accumulo/core/iterators/user/GrepIteratorTest.java
+++
b/core/src/test/java/org/apache/accumulo/core/iterators/user/GrepIteratorTest.java
@@ -92,6 +92,7 @@ public class GrepIteratorTest {
GrepIterator.setTerm(is, "ab");
gi.init(new SortedMapIterator(input), is.getOptions(), null);
gi.seek(new Range(), EMPTY_COL_FAMS, false);
+ GrepIterator.matchColumnVisibility(is, true);
checkEntries(gi, output);
GrepIterator.setTerm(is, "cde");
gi.init(new SortedMapIterator(input), is.getOptions(), null);
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java
index bc6e10651e..2695f572f3 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java
@@ -119,13 +119,15 @@ public class GrepCommand extends ScanCommand {
final IteratorSetting grep = new IteratorSetting(prio, name,
GrepIterator.class);
GrepIterator.setTerm(grep, term);
GrepIterator.setNegate(grep, negate);
+ GrepIterator.matchColumnVisibility(grep, true); // override GrepIterator
default
scanner.addScanIterator(grep);
}
@Override
public String description() {
- return "searches each row, column family, column qualifier, visibility,
and value in a"
- + " table for a substring (not a regular expression), in parallel, on
the server side";
+ return "searches each row, column family, column qualifier, visibility
(since 2.1.3),"
+ + " and value in a table for a substring (not a regular expression),
in parallel,"
+ + " on the server side";
}
@Override