You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2018/04/26 20:27:10 UTC

[accumulo] branch master updated: Expose negation to shell grep command (#446)

This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b74ba7  Expose negation to shell grep command (#446)
9b74ba7 is described below

commit 9b74ba74da69ab7e942da34453eb8ae5757d0af1
Author: alerman <al...@gmail.com>
AuthorDate: Thu Apr 26 16:27:05 2018 -0400

    Expose negation to shell grep command (#446)
---
 .../org/apache/accumulo/shell/commands/EGrepCommand.java    |  3 ++-
 .../org/apache/accumulo/shell/commands/GrepCommand.java     | 13 +++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/EGrepCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/EGrepCommand.java
index 57638fc..1395362 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/EGrepCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/EGrepCommand.java
@@ -31,13 +31,14 @@ public class EGrepCommand extends GrepCommand {
 
   @Override
   protected void setUpIterator(final int prio, final String name, final String term,
-      final BatchScanner scanner, CommandLine cl) throws IOException {
+      final BatchScanner scanner, CommandLine cl, boolean negate) throws IOException {
     if (prio < 0) {
       throw new IllegalArgumentException("Priority < 0 " + prio);
     }
     final IteratorSetting si = new IteratorSetting(prio, name, RegExFilter.class);
     RegExFilter.setRegexs(si, term, term, term, term, true,
         cl.hasOption(matchSubstringOption.getOpt()));
+    RegExFilter.setNegate(si, negate);
     scanner.addScanIterator(si);
   }
 
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 d2ccad1..1ec8ca1 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
@@ -37,6 +37,7 @@ import org.apache.commons.cli.Options;
 public class GrepCommand extends ScanCommand {
 
   private Option numThreadsOpt;
+  private Option negateOpt;
 
   @Override
   public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
@@ -57,6 +58,11 @@ public class GrepCommand extends ScanCommand {
       if (cl.hasOption(numThreadsOpt.getOpt())) {
         numThreads = Integer.parseInt(cl.getOptionValue(numThreadsOpt.getOpt()));
       }
+
+      boolean negate = false;
+      if (cl.hasOption(negateOpt.getOpt())) {
+        negate = true;
+      }
       final Authorizations auths = getAuths(cl, shellState);
       final BatchScanner scanner = shellState.getConnector().createBatchScanner(tableName, auths,
           numThreads);
@@ -68,7 +74,7 @@ public class GrepCommand extends ScanCommand {
 
       for (int i = 0; i < cl.getArgs().length; i++) {
         setUpIterator(Integer.MAX_VALUE - cl.getArgs().length + i, "grep" + i, cl.getArgs()[i],
-            scanner, cl);
+            scanner, cl, negate);
       }
       try {
         // handle columns
@@ -87,12 +93,13 @@ public class GrepCommand extends ScanCommand {
   }
 
   protected void setUpIterator(final int prio, final String name, final String term,
-      final BatchScanner scanner, CommandLine cl) throws IOException {
+      final BatchScanner scanner, CommandLine cl, boolean negate) throws IOException {
     if (prio < 0) {
       throw new IllegalArgumentException("Priority < 0 " + prio);
     }
     final IteratorSetting grep = new IteratorSetting(prio, name, GrepIterator.class);
     GrepIterator.setTerm(grep, term);
+    GrepIterator.setNegate(grep, negate);
     scanner.addScanIterator(grep);
   }
 
@@ -106,7 +113,9 @@ public class GrepCommand extends ScanCommand {
   public Options getOptions() {
     final Options opts = super.getOptions();
     numThreadsOpt = new Option("nt", "num-threads", true, "number of threads to use");
+    negateOpt = new Option("v", "negate", false, "only include rows without search term");
     opts.addOption(numThreadsOpt);
+    opts.addOption(negateOpt);
     return opts;
   }
 

-- 
To stop receiving notification emails like this one, please contact
ctubbsii@apache.org.