You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2018/04/26 20:27:07 UTC

[GitHub] ctubbsii closed pull request #446: Expose negation to shell

ctubbsii closed pull request #446: Expose negation to shell
URL: https://github.com/apache/accumulo/pull/446
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 57638fcf37..13953624b5 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 @@
 
   @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 d2ccad1cbc..1ec8ca1d60 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 @@
 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 int execute(final String fullCommand, final CommandLine cl, final Shell s
       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 int execute(final String fullCommand, final CommandLine cl, final Shell s
 
       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 int execute(final String fullCommand, final CommandLine cl, final Shell s
   }
 
   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 String description() {
   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;
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services