accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmil...@apache.org
Subject [accumulo] branch master updated: Update Shell bulk import command. Closes #470
Date Fri, 27 Jul 2018 15:26:15 GMT
This is an automated email from the ASF dual-hosted git repository.

mmiller 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 02eaab9  Update Shell bulk import command. Closes #470
02eaab9 is described below

commit 02eaab99469ddfcf9cd0ddd4f11bbf4b4e6d2c69
Author: Mike Miller <mmiller@apache.org>
AuthorDate: Fri Jul 27 11:26:13 2018 -0400

    Update Shell bulk import command. Closes #470
    
    The shell importdirectory command will now support both the old and new
    versions of bulk import, based on the number of arguments provided.
---
 .../shell/commands/ImportDirectoryCommand.java     | 43 ++++++++++++++++++----
 1 file changed, 35 insertions(+), 8 deletions(-)

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 ec1576b..0429794 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 java.io.IOException;
 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 @@ public class ImportDirectoryCommand extends Command {
   @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 class ImportDirectoryCommand extends Command {
       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";
   }
 
 }


Mime
View raw message