incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Adding new create table command with full create table support.
Date Mon, 26 Aug 2013 11:48:13 GMT
Updated Branches:
  refs/heads/master 426d3c3b7 -> 2af17926f


Adding new create table command with full create table support.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/2af17926
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/2af17926
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/2af17926

Branch: refs/heads/master
Commit: 2af17926f95af92c3d0ab8cd006500bfc4d36f80
Parents: 426d3c3
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Aug 26 07:47:25 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Aug 26 07:47:25 2013 -0400

----------------------------------------------------------------------
 .../apache/blur/shell/CreateTableCommand.java   | 87 +++++++++++++++++---
 docs/using-blur.html                            |  4 +-
 2 files changed, 77 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2af17926/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java
index 381b485..c337d74 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/CreateTableCommand.java
@@ -19,29 +19,79 @@
 package org.apache.blur.shell;
 
 import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.TableDescriptor;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
 
 public class CreateTableCommand extends Command {
   @Override
   public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
       BlurException {
-    if (args.length != 4) {
-      throw new CommandException("Invalid args: " + help());
+    CommandLine cmd = CreateTableCommandHelper.parse(args, out);
+    if (cmd == null) {
+      throw new CommandException(name() + " missing required arguments");
     }
-
-    String tablename = args[1];
-    String tableuri = args[2];
-    int shardCount = Integer.parseInt(args[3]);
-
     TableDescriptor td = new TableDescriptor();
-    td.setTableUri(tableuri);
+
     td.setCluster(Main.getCluster(client));
-    td.setName(tablename);
-    td.setShardCount(shardCount);
+    td.setName(cmd.getOptionValue("t"));
+    td.setShardCount(Integer.parseInt(cmd.getOptionValue("c")));
+
+    if (cmd.hasOption("b")) {
+      td.setBlockCaching(false);
+    }
+    if (cmd.hasOption("B")) {
+      String[] optionValues = cmd.getOptionValues("B");
+      Set<String> blockCachingFileTypes = new HashSet<String>();
+      if (optionValues != null) {
+        blockCachingFileTypes.addAll(Arrays.asList(cmd.getOptionValues("B")));
+      }
+      td.setBlockCachingFileTypes(blockCachingFileTypes);
+    }
+    if (cmd.hasOption("mfi")) {
+      td.setDefaultMissingFieldLessIndexing(false);
+    }
+    if (cmd.hasOption("mft")) {
+      String defaultMissingFieldType = cmd.getOptionValue("mft");
+      td.setDefaultMissingFieldType(defaultMissingFieldType);
+    }
+    if (cmd.hasOption("mfp")) {
+      Map<String, String> defaultMissingFieldProps = getProps(cmd, "mfp");
+      td.setDefaultMissingFieldProps(defaultMissingFieldProps);
+    }
+    if (cmd.hasOption("d")) {
+      td.setEnabled(false);
+    }
+    if (cmd.hasOption("p")) {
+      Map<String, String> tableProperties = getProps(cmd, "p");
+      td.setTableProperties(tableProperties);
+    }
+    if (cmd.hasOption("s")) {
+      td.setStrictTypes(true);
+    }
+    if (cmd.hasOption("r")) {
+      td.setReadOnly(true);
+    }
+    if (cmd.hasOption("l")) {
+      String tableUri = cmd.getOptionValue("l");
+      td.setReadOnly(true);
+      td.setTableUri(tableUri);
+    }
+    if (cmd.hasOption("P")) {
+      td.setPreCacheCols(Arrays.asList(cmd.getOptionValues("P")));
+    }
+    if (cmd.hasOption("S")) {
+      td.setSimilarityClass(cmd.getOptionValue("S"));
+    }
 
     if (Main.debug) {
       out.println(td.toString());
@@ -51,18 +101,31 @@ public class CreateTableCommand extends Command {
     client.createTable(td);
   }
 
+  private Map<String, String> getProps(CommandLine cmd, String opt) {
+    Map<String, String> props = new HashMap<String, String>();
+    Option[] options = cmd.getOptions();
+    for (Option option : options) {
+      if (option.getOpt().equals(opt)) {
+        String[] values = option.getValues();
+        props.put(values[0], values[1]);
+      }
+    }
+    return props;
+  }
+
   @Override
   public String description() {
-    return "Create the named table.";
+    return "Create the named table.  Run -h for full argument list.";
   }
 
   @Override
   public String usage() {
-    return "<tablename> <tableuri> <shardcount>";
+    return "-t <tablename> -c <shardcount>";
   }
 
   @Override
   public String name() {
     return "create";
   }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2af17926/docs/using-blur.html
----------------------------------------------------------------------
diff --git a/docs/using-blur.html b/docs/using-blur.html
index 38b2f8f..f2b19d9 100644
--- a/docs/using-blur.html
+++ b/docs/using-blur.html
@@ -274,8 +274,8 @@ The following rules are used when interacting with the shell:
 </p>
 <h3 id="shell_table_commands">Table Commands</h3>
 <h4 id="shell_command_create">create</h4>
-<p>Description: Create the named table.<br/>
-<pre><code class="bash">create &lt;tablename&gt; &lt;tableuri&gt;
&lt;shardcount&gt;</code></pre></p>
+<p>Description: Create the named table.  Run -h for full argument list.<br/>
+<pre><code class="bash">create -t &lt;tablename&gt; -c &lt;shardcount&gt;</code></pre></p>
 <h4 id="shell_command_enable">enable</h4>
 <p>Description: Enable the named table.<br/>
 <pre><code class="bash">enable &lt;tablename&gt;</code></pre></p>


Mime
View raw message