milleruntime closed pull request #570: Update Shell bulk import command. Closes 
#470
URL: https://github.com/apache/accumulo/pull/570
 
 
   

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/ImportDirectoryCommand.java
 
b/shell/src/main/java/org/apache/accumulo/shell/commands/ImportDirectoryCommand.java
index ec1576b01f..0429794f17 100644
--- 
a/shell/src/main/java/org/apache/accumulo/shell/commands/ImportDirectoryCommand.java
+++ 
b/shell/src/main/java/org/apache/accumulo/shell/commands/ImportDirectoryCommand.java
@@ -21,6 +21,7 @@
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.admin.TableOperations;
 import org.apache.accumulo.shell.Shell;
 import org.apache.accumulo.shell.Shell.Command;
 import org.apache.commons.cli.CommandLine;
@@ -30,7 +31,9 @@
   @Override
   public String description() {
     return "bulk imports an entire directory of data files to the current"
-        + " table. The boolean argument determines if accumulo sets the time.";
+        + " table. The boolean argument determines if accumulo sets the time. "
+        + "Passing 3 arguments will use the old bulk import.  The new bulk 
import only takes 2 "
+        + "arguments: <directory> true|false";
   }
 
   @Override
@@ -38,23 +41,47 @@ public int execute(final String fullCommand, final 
CommandLine cl, final Shell s
       throws IOException, AccumuloException, AccumuloSecurityException, 
TableNotFoundException {
     shellState.checkTableState();
 
-    String dir = cl.getArgs()[0];
-    String failureDir = cl.getArgs()[1];
-    final boolean setTime = Boolean.parseBoolean(cl.getArgs()[2]);
+    String[] args = cl.getArgs();
+    String dir = args[0];
+    boolean setTime;
+
+    // new bulk import only takes 2 args
+    if (args.length == 2) {
+      setTime = Boolean.parseBoolean(cl.getArgs()[1]);
+      TableOperations.ImportExecutorOptions bulk = 
shellState.getConnector().tableOperations()
+          .addFilesTo(shellState.getTableName()).from(dir);
+      if (setTime)
+        bulk.settingLogicalTime().load();
+      else
+        bulk.load();
+    } else if (args.length == 3) {
+      // warn using deprecated bulk import
+      Shell.log.warn(
+          "Deprecated since 2.0.0. New bulk import technique does not take a 
failure directory "
+              + "as an argument.");
+      String failureDir = args[1];
+      setTime = Boolean.parseBoolean(cl.getArgs()[2]);
+      
shellState.getConnector().tableOperations().importDirectory(shellState.getTableName(),
 dir,
+          failureDir, setTime);
+      return 0;
+    } else {
+      shellState.printException(
+          new IllegalArgumentException(String.format("Expected 2 or 3 
arguments. There %s %d.",
+              args.length == 1 ? "was" : "were", args.length)));
+      printHelp(shellState);
+    }
 
-    
shellState.getConnector().tableOperations().importDirectory(shellState.getTableName(),
 dir,
-        failureDir, setTime);
     return 0;
   }
 
   @Override
   public int numArgs() {
-    return 3;
+    return Shell.NO_FIXED_ARG_LENGTH_CHECK;
   }
 
   @Override
   public String usage() {
-    return getName() + " <directory> <failureDirectory> true|false";
+    return getName() + " <directory> [failureDirectory] true|false";
   }
 
 }


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to