incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: More fo the shell commands are fixed. Create, enable, disable, remove, list, describe and search all work.
Date Wed, 02 Jan 2013 03:27:33 GMT
Updated Branches:
  refs/heads/0.2-dev f92d94a9b -> eb5421c88


More fo the shell commands are fixed.  Create, enable, disable, remove, list, describe and
search all work.


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

Branch: refs/heads/0.2-dev
Commit: eb5421c8896503b83b1906661c1e1261a061108c
Parents: f92d94a
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Jan 1 22:26:22 2013 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Jan 1 22:26:22 2013 -0500

----------------------------------------------------------------------
 .../java/org/apache/blur/shell/AddCommand.java     |    4 +-
 .../main/java/org/apache/blur/shell/Command.java   |    4 +-
 .../java/org/apache/blur/shell/CreateCommand.java  |   32 +--
 .../org/apache/blur/shell/DescribeCommand.java     |    5 +-
 .../org/apache/blur/shell/DisableTableCommand.java |    5 +-
 .../org/apache/blur/shell/EnableTableCommand.java  |    5 +-
 .../org/apache/blur/shell/GetDocumentCommand.java  |   61 ----
 .../apache/blur/shell/IndexAccessLogCommand.java   |    5 +-
 .../org/apache/blur/shell/ListTablesCommand.java   |    5 +-
 .../src/main/java/org/apache/blur/shell/Main.java  |   19 +-
 .../org/apache/blur/shell/RemoveTableCommand.java  |    5 +-
 .../org/apache/blur/shell/SchemaTableCommand.java  |    5 +-
 .../java/org/apache/blur/shell/SearchCommand.java  |  239 +++++++++++++--
 .../blur/shell/ShardServerLayoutCommand.java       |    5 +-
 .../org/apache/blur/shell/TableStatsCommand.java   |    5 +-
 .../java/org/apache/blur/shell/UpdateCommand.java  |    5 +-
 .../java/org/apache/blur/thrift/StringField.java   |   93 ++++++
 .../java/org/apache/blur/thrift/TextField.java     |   93 ++++++
 18 files changed, 457 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/AddCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/AddCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/AddCommand.java
index 03dcf35..71c989a 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/AddCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/AddCommand.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -30,7 +32,7 @@ public class AddCommand extends Command {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
     if (args.length != 7) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/Command.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/Command.java b/src/blur-shell/src/main/java/org/apache/blur/shell/Command.java
index b0143c0..af548f5 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/Command.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/Command.java
@@ -27,10 +27,12 @@ import java.util.Map;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import jline.console.ConsoleReader;
 import jline.console.completer.Completer;
 
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
+import org.apache.commons.cli.ParseException;
 import org.apache.thrift.TException;
 
 public abstract class Command implements Completer {
@@ -57,7 +59,7 @@ public abstract class Command implements Completer {
     return client;
   }
 
-  public abstract void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException;
+  public abstract void doit(PrintWriter out, String[] args, ConsoleReader reader) throws
CommandException, TException, BlurException, ParseException;
 
   public abstract String help();
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/CreateCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/CreateCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/CreateCommand.java
index 5ad402e..8c49ae4 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/CreateCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/CreateCommand.java
@@ -19,6 +19,9 @@
 package org.apache.blur.shell;
 
 import java.io.PrintWriter;
+import java.util.List;
+
+import jline.console.ConsoleReader;
 
 import org.apache.blur.thrift.generated.Analyzer;
 import org.apache.blur.thrift.generated.Blur.Iface;
@@ -41,46 +44,35 @@ public class CreateCommand extends Command {
   private static final String CREATE = "create";
   private static final String DISABLED = "disabled";
   private static final String READONLY = "readonly";
-  private static final String SHARDS = "shards";
-  private static final String PATH = "path";
-  private static final String NAME = "name";
   private static final String HELP = "help";
-  private String[] requiredOptions = new String[] { NAME, PATH, SHARDS };
 
+  @SuppressWarnings("unchecked")
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     Options options = new Options();
     options.addOption("h", HELP, false, "Print the help for this command.");
-    options.addOption("t", NAME, true, "The name of the new table. (Required)");
-    options.addOption("p", PATH, true, "The storage path of the new table (e.g. hdfs://hostname/path).
(Required)");
-    options.addOption("s", SHARDS, true, "The number of indexes shards. (Required)");
     options.addOption("r", READONLY, false, "The make the table in read only mode.");
     options.addOption("d", DISABLED, false, "Disable the newly created table.");
 
     CommandLineParser parser = new PosixParser();
     try {
       CommandLine line = parser.parse(options, args);
+      List<String> argList = line.getArgList();
       boolean printHelp = false;
-      if (line.hasOption(HELP)) {
+      if (line.hasOption(HELP) || argList.size() != 4) {
         printHelp = true;
       }
 
-      for (String n : requiredOptions) {
-        if (!line.hasOption(n)) {
-          System.err.println("Missing required argument (" + options.getOption(n) + ")");
-          printHelp = true;
-        }
-      }
-
       if (printHelp) {
         HelpFormatter formatter = new HelpFormatter();
-        formatter.printHelp(getName(), options);
+        formatter.printHelp(getName() + " <table name> <table path> <number
of shards>", options);
         return;
       }
 
-      String tablename = line.getOptionValue(NAME);
-      String path = line.getOptionValue(PATH);
-      String shards = line.getOptionValue(SHARDS);
+      String tablename = argList.get(1);
+      String path = argList.get(2);
+      String shards = argList.get(3);
 
       Analyzer analyzer = new Analyzer();
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/DescribeCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/DescribeCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/DescribeCommand.java
index 8b45529..9c803d3 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/DescribeCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/DescribeCommand.java
@@ -24,6 +24,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Analyzer;
 import org.apache.blur.thrift.generated.AnalyzerSubType;
 import org.apache.blur.thrift.generated.AnalyzerType;
@@ -38,7 +40,8 @@ public class DescribeCommand extends TableSingleArgumentCommand {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length != 2) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/DisableTableCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/DisableTableCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/DisableTableCommand.java
index ef2377d..3b9d58e 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/DisableTableCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/DisableTableCommand.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -32,7 +34,8 @@ public class DisableTableCommand extends TableSingleArgumentCommand {
   private static final String DISABLE = "disable";
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length != 2) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/EnableTableCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/EnableTableCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/EnableTableCommand.java
index 66efbc6..0664fe4 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/EnableTableCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/EnableTableCommand.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -32,7 +34,8 @@ public class EnableTableCommand extends TableSingleArgumentCommand {
   private static final String ENABLE = "enable";
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length != 2) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/GetDocumentCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/GetDocumentCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/GetDocumentCommand.java
deleted file mode 100644
index e283e43..0000000
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/GetDocumentCommand.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.blur.shell;
-
-import java.io.PrintWriter;
-
-import org.apache.blur.thrift.generated.Blur.Iface;
-import org.apache.blur.thrift.generated.BlurException;
-import org.apache.thrift.TException;
-
-public class GetDocumentCommand extends Command {
-  public GetDocumentCommand(Iface client) {
-    super(client);
-  }
-
-  @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
-    if (args.length != 3) {
-      throw new CommandException("Invalid args: " + help());
-    }
-    String tablename = args[1];
-    String rowId = args[2];
-
-    throw new CommandException("Needs to be implemented");
-
-    //
-    // Selector selector = new Selector();
-    // selector.setRowId(rowId);
-    // FetchResult fetchRow = client.fetchRow(tablename, selector);
-    // FetchRowResult rowResult = fetchRow.getRowResult();
-    // Row row = rowResult.getRow();
-    //
-    // out.println(row);
-  }
-
-  @Override
-  public String help() {
-    return "display the specified row, args; tablename query";
-  }
-
-  @Override
-  public String getName() {
-    return "get";
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/IndexAccessLogCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/IndexAccessLogCommand.java
b/src/blur-shell/src/main/java/org/apache/blur/shell/IndexAccessLogCommand.java
index 48cce2c..28082e0 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/IndexAccessLogCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/IndexAccessLogCommand.java
@@ -21,6 +21,8 @@ package org.apache.blur.shell;
 import java.io.File;
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -31,7 +33,8 @@ public class IndexAccessLogCommand extends Command {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length < 6) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java
index 79d4e3b..c10e890 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -30,7 +32,8 @@ public class ListTablesCommand extends Command {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     for (String table : client.tableList()) {
       System.out.println(table);
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/Main.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/Main.java b/src/blur-shell/src/main/java/org/apache/blur/shell/Main.java
index dd5ec4b..e5694c4 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/Main.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/Main.java
@@ -18,18 +18,13 @@
 
 package org.apache.blur.shell;
 
-import java.io.IOException;
 import java.io.PrintWriter;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.TimeUnit;
 
 import jline.console.ConsoleReader;
 import jline.console.completer.Completer;
-import jline.console.completer.CompletionHandler;
-import jline.console.completer.FileNameCompleter;
-import jline.console.completer.StringsCompleter;
 
 import org.apache.blur.shell.Command.CommandException;
 import org.apache.blur.shell.Main.QuitCommand.QuitCommandException;
@@ -60,7 +55,7 @@ public class Main {
     }
 
     @Override
-    public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+    public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
       if (debug == true) {
         debug = false;
       } else {
@@ -88,7 +83,7 @@ public class Main {
     }
 
     @Override
-    public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+    public void doit(PrintWriter out,  String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
       if (timed == true) {
         timed = false;
       } else {
@@ -115,7 +110,7 @@ public class Main {
     }
 
     @Override
-    public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+    public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
       out.println("Available commands:");
       for (Entry<String, Command> e : commands.entrySet()) {
         out.println("  " + e.getKey() + " - " + e.getValue().help());
@@ -146,7 +141,7 @@ public class Main {
     }
 
     @Override
-    public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+    public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
       throw new QuitCommandException();
     }
 
@@ -195,19 +190,20 @@ public class Main {
       PrintWriter out = new PrintWriter(reader.getOutput());
       try {
         while ((line = reader.readLine()) != null) {
+          
           line = line.trim();
           // ignore empty lines and comments
           if (line.length() == 0 || line.startsWith("#")) {
             continue;
           }
-          String[] commandArgs = line.split("\\s");
+          String[] commandArgs = line.split("\\s+");
           Command command = commands.get(commandArgs[0]);
           if (command == null) {
             out.println("unknown command \"" + commandArgs[0] + "\"");
           } else {
             long start = System.nanoTime();
             try {
-              command.doit(out, client, commandArgs);
+              command.doit(out, commandArgs,reader);
             } catch (QuitCommandException e) {
               // exit gracefully
               System.exit(0);
@@ -253,7 +249,6 @@ public class Main {
     // builder.put("tablestats", new TableStatsCommand());
     // builder.put("schema", new SchemaTableCommand());
     add(builder, new SearchCommand(client));
-    add(builder, new GetDocumentCommand(client));
     add(builder, new AddCommand(client));
     add(builder, new UpdateCommand(client));
     // builder.put("indexaccesslog", new IndexAccessLogCommand());

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java
index fc3c5f8..0b1aec3 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/RemoveTableCommand.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -30,7 +32,8 @@ public class RemoveTableCommand extends TableSingleArgumentCommand {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length != 2) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java
index 5aa1515..b740cf0 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -30,7 +32,8 @@ public class SchemaTableCommand extends Command {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length != 2) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java
index 52b8d3e..2008cf5 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/SearchCommand.java
@@ -19,54 +19,130 @@
 package org.apache.blur.shell;
 
 import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
 
+import jline.Terminal;
+import jline.console.ConsoleReader;
+
+import org.apache.blur.thrift.BlurClient;
+import org.apache.blur.thrift.StringField;
+import org.apache.blur.thrift.TextField;
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.Document;
+import org.apache.blur.thrift.generated.Field;
+import org.apache.blur.thrift.generated.Query;
+import org.apache.blur.thrift.generated.QueryArgs;
+import org.apache.blur.thrift.generated.QueryType;
+import org.apache.blur.thrift.generated.ScoreDoc;
+import org.apache.blur.thrift.generated.Session;
+import org.apache.blur.thrift.generated.TYPE;
+import org.apache.blur.thrift.generated.TopFieldDocs;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
 import org.apache.thrift.TException;
 
 public class SearchCommand extends TableSingleArgumentCommand {
+
+  private static final String DOCLOC = "docloc";
+  private static final String HELP = "help";
+  private static final String BOOST = "boost";
+  private static final String FIELD = "field";
+  private static final String TYPE = "type";
+
+  public static void main(String[] args) throws BlurException, CommandException, TException,
ParseException {
+    Iface client = BlurClient.getClient("127.0.0.1:40020");
+    SearchCommand command = new SearchCommand(client);
+    PrintWriter out = new PrintWriter(System.out);
+    command.doit(out, new String[] { "search", "test123", "f1:test3" }, null);
+    out.flush();
+    out.close();
+  }
+
   public SearchCommand(Iface client) {
     super(client);
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
-    if (args.length < 3) {
-      throw new CommandException("Invalid args: " + help());
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException, ParseException {
+    int maxLineWidth = 120;
+    if (reader != null) {
+      Terminal terminal = reader.getTerminal();
+      maxLineWidth = terminal.getWidth() - 1;
+    }
+
+    Options options = new Options();
+    options.addOption("h", HELP, false, "Print the help for this command.");
+    options.addOption("f", FIELD, true, "Fields to fetch during retrieval.");
+    options.addOption("t", TYPE, false, "Show field type.");
+    options.addOption("b", BOOST, false, "Show field boost.");
+    options.addOption("l", DOCLOC, false, "Show document locations.");
+
+    CommandLineParser parser = new PosixParser();
+    CommandLine line = parser.parse(options, args);
+    String[] otherArgs = line.getArgs();
+
+    boolean printHelp = false;
+    if (line.hasOption(HELP) || otherArgs.length < 3) {
+      printHelp = true;
     }
-    String tablename = args[1];
-    String query = "";
-    for (int i = 2; i < args.length; i++) {
-      query += args[i] + " ";
+
+    if (printHelp) {
+      HelpFormatter formatter = new HelpFormatter();
+      formatter.printHelp(getName() + " <options> table query string ...", options);
+      return;
+    }
+
+    boolean showBoost = line.hasOption(BOOST);
+    boolean showType = line.hasOption(TYPE);
+    boolean showDocLocations = line.hasOption(DOCLOC);
+    String[] fieldNames = line.getOptionValues(FIELD);
+
+    Iface client = getClient();
+
+    String tablename = otherArgs[1];
+    String queryStr = "";
+    for (int i = 2; i < otherArgs.length; i++) {
+      queryStr += otherArgs[i] + " ";
     }
 
+    Query query = new Query();
+    query.setType(QueryType.STRING);
+    query.setQueryString(queryStr);
 
-    // BlurQuery blurQuery = new BlurQuery();
-    // SimpleQuery simpleQuery = new SimpleQuery();
-    // simpleQuery.setQueryStr(query);
-    // blurQuery.setSimpleQuery(simpleQuery);
-    // blurQuery.setSelector(new Selector());
-    //
-    // // QueryArgs queryArgs = BlurUtil
-    //
-    // QueryArgs queryArgs = new QueryArgs();
-    // queryArgs.setQuery(ThriftLuceneConversion.toBytes(new
-    // MatchAllDocsQuery()));
-    //
-    // if (Main.debug) {
-    // out.println(blurQuery);
-    // }
-    //
-    // Session session = client.openReadSession(tablename);
-    // List<TopFieldDocs> topDocs = client.search(session, queryArgs);
-    //
-    // if (Main.debug) {
-    // out.println("shardinfo: " + blurResults.getShardInfo());
-    // }
-    //
-    // for (BlurResult result : blurResults.getResults()) {
-    // out.println(result);
-    // }
+    QueryArgs queryArgs = new QueryArgs();
+    queryArgs.setQuery(query);
+    queryArgs.setAggregateResults(true);
+
+    Session session = client.openReadSession(tablename);
+    List<TopFieldDocs> topDocs = client.search(session, queryArgs);
+    if (topDocs.size() != 1) {
+      throw new CommandException("Search returned [" + topDocs.size() + "] topfielddocs,
should have only returned 1.");
+    }
+
+    TopFieldDocs topFieldDocs = topDocs.iterator().next();
+    List<ScoreDoc> scoreDocs = topFieldDocs.getScoreDocs();
+    List<Long> docLocations = new ArrayList<Long>();
+    for (ScoreDoc scoreDoc : scoreDocs) {
+      docLocations.add(scoreDoc.getDocLocation());
+    }
+    List<Document> docs;
+    if (fieldNames != null && fieldNames.length > 0) {
+      docs = client.doc(session, docLocations, new HashSet<String>(Arrays.asList(fieldNames)));
+    } else {
+      docs = client.doc(session, docLocations, null);
+    }
+    long totalHits = topFieldDocs.getTotalHits();
+    out.println("Totalhits " + totalHits);
+    print(docs, docLocations, showDocLocations, showBoost, showType, out, maxLineWidth);
+    client.closeReadSession(session);
   }
 
   @Override
@@ -78,4 +154,101 @@ public class SearchCommand extends TableSingleArgumentCommand {
   public String getName() {
     return "search";
   }
+
+  private void print(List<Document> docs, List<Long> docLocations, boolean showDocLocations,
boolean showBoost, boolean showType, PrintWriter out, int maxLineWidth) {
+    List<String> fieldNames = new ArrayList<String>();
+    List<String> fieldTypes = new ArrayList<String>();
+    for (Document document : docs) {
+      List<Field> fields = document.getFields();
+      for (Field field : fields) {
+        String name = field.getName();
+        String type = field.getType().name();
+        if (!fieldTypes.contains(type)) {
+          fieldTypes.add(type);
+        }
+        if (!fieldNames.contains(name)) {
+          fieldNames.add(name);
+        }
+      }
+    }
+
+    int maxFieldNameLength = maxLength(fieldNames);
+    int boostWidth = 4;
+    int typeNameWidth = maxLength(fieldTypes);
+    int fieldSep = 3;
+    int valueMaxWidth;
+    int metaDataWidth;
+
+    if (showBoost && showType) {
+      metaDataWidth = maxFieldNameLength + boostWidth + typeNameWidth + (fieldSep * 3);
+    } else if (showBoost) {
+      metaDataWidth = maxFieldNameLength + boostWidth + (fieldSep * 2);
+    } else if (showType) {
+      metaDataWidth = maxFieldNameLength + typeNameWidth + (fieldSep * 2);
+    } else {
+      metaDataWidth = maxFieldNameLength + fieldSep;
+    }
+    valueMaxWidth = maxLineWidth - metaDataWidth;
+    int fieldPaging = metaDataWidth - fieldSep;
+    for (Document document : docs) {
+      for (int i = 0; i < maxLineWidth; i++) {
+        out.print('-');
+      }
+      out.println();
+      for (Field field : document.getFields()) {
+        String name = field.getName();
+        double boost = field.getBoost();
+        TYPE type = field.getType();
+        String typeStr = type.name();
+
+        String valueStr = toString(field);
+
+        for (int i = 0; i < valueStr.length(); i += valueMaxWidth) {
+          int max = Math.min(i + valueMaxWidth, valueStr.length());
+          String displayValue = valueStr.substring(i, max);
+          if (i == 0) {
+            if (showBoost && showType) {
+              out.printf("%" + maxFieldNameLength + "s | %" + boostWidth + ".2f | %" + typeNameWidth
+ "s | %." + valueMaxWidth + "s%n", name, boost, typeStr, displayValue);
+            } else if (showBoost) {
+              out.printf("%" + maxFieldNameLength + "s | %" + boostWidth + ".2f | %." + valueMaxWidth
+ "s%n", name, boost, displayValue);
+            } else if (showType) {
+              out.printf("%" + maxFieldNameLength + "s | %" + typeNameWidth + "s | %." +
valueMaxWidth + "s%n", name, typeStr, displayValue);
+            } else {
+              out.printf("%" + maxFieldNameLength + "s | %." + valueMaxWidth + "s%n", name,
displayValue);
+            }
+          } else {
+            for (int c = 0; c < fieldPaging; c++) {
+              out.print(' ');
+            }
+            out.print(" | ");
+            out.println(displayValue);
+          }
+        }
+      }
+    }
+  }
+
+  private String toString(Field field) {
+    byte[] value = field.getValue();
+    if (value == null) {
+      return null;
+    }
+    TYPE type = field.getType();
+    switch (type) {
+    case TEXT:
+      return new TextField(field).getValueString();
+    case STRING:
+      return new StringField(field).getValueString();
+    default:
+      throw new RuntimeException("Not supported");
+    }
+  }
+
+  private int maxLength(List<String> fieldNames) {
+    int maxFieldNameLength = 0;
+    for (String fieldName : fieldNames) {
+      maxFieldNameLength = Math.max(maxFieldNameLength, fieldName.length());
+    }
+    return maxFieldNameLength;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/ShardServerLayoutCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/ShardServerLayoutCommand.java
b/src/blur-shell/src/main/java/org/apache/blur/shell/ShardServerLayoutCommand.java
index 7dd9d3f..322e066 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/ShardServerLayoutCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/ShardServerLayoutCommand.java
@@ -21,6 +21,8 @@ package org.apache.blur.shell;
 import java.io.PrintWriter;
 import java.util.Map;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.ShardLayout;
@@ -32,7 +34,8 @@ public class ShardServerLayoutCommand extends Command {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length != 2) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java
index 04cb169..0258779 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/TableStatsCommand.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -30,7 +32,8 @@ public class TableStatsCommand extends Command {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length != 2) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-shell/src/main/java/org/apache/blur/shell/UpdateCommand.java
----------------------------------------------------------------------
diff --git a/src/blur-shell/src/main/java/org/apache/blur/shell/UpdateCommand.java b/src/blur-shell/src/main/java/org/apache/blur/shell/UpdateCommand.java
index 4cd07b7..98c818e 100644
--- a/src/blur-shell/src/main/java/org/apache/blur/shell/UpdateCommand.java
+++ b/src/blur-shell/src/main/java/org/apache/blur/shell/UpdateCommand.java
@@ -20,6 +20,8 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.console.ConsoleReader;
+
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.thrift.TException;
@@ -30,7 +32,8 @@ public class UpdateCommand extends Command {
   }
 
   @Override
-  public void doit(PrintWriter out, Iface client, String[] args) throws CommandException,
TException, BlurException {
+  public void doit(PrintWriter out, String[] args, ConsoleReader reader) throws CommandException,
TException, BlurException {
+    Iface client = getClient();
     if (args.length != 7) {
       throw new CommandException("Invalid args: " + help());
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java
new file mode 100644
index 0000000..656d109
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java
@@ -0,0 +1,93 @@
+package org.apache.blur.thrift;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+
+import org.apache.blur.thrift.generated.Field;
+import org.apache.blur.thrift.generated.TYPE;
+
+@SuppressWarnings("serial")
+public class StringField extends Field {
+
+  private static final String UTF_8 = "UTF-8";
+
+  public StringField(String name, String value) {
+    super(name, toByteBuffer(value), TYPE.STRING, 1.0);
+  }
+
+  private static ByteBuffer toByteBuffer(String value) {
+    try {
+      return ByteBuffer.wrap(value.getBytes("UTF-8"));
+    } catch (UnsupportedEncodingException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public StringField() {
+
+  }
+
+  public StringField(Field field) {
+    super(field.name, field.value, field.type, field.boost);
+    if (field.getType() != TYPE.STRING) {
+      throw new RuntimeException("Field [" + field + "] is not of type String.");
+    }
+  }
+
+  public String getValueString() {
+    try {
+      return new String(getValue(), UTF_8);
+    } catch (UnsupportedEncodingException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public StringField setValueString(String value) {
+    try {
+      setValue(value.getBytes(UTF_8));
+    } catch (UnsupportedEncodingException e) {
+      throw new RuntimeException(e);
+    }
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("StringField(");
+    boolean first = true;
+
+    sb.append("name:");
+    if (this.name == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.name);
+    }
+    first = false;
+    if (!first)
+      sb.append(", ");
+    sb.append("value:");
+    if (this.value == null) {
+      sb.append("null");
+    } else {
+      sb.append(getValueString());
+    }
+    first = false;
+    if (!first)
+      sb.append(", ");
+    sb.append("type:");
+    if (this.type == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.type);
+    }
+    first = false;
+    if (!first)
+      sb.append(", ");
+    sb.append("boost:");
+    sb.append(this.boost);
+    first = false;
+    sb.append(")");
+    return sb.toString();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eb5421c8/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java
new file mode 100644
index 0000000..6963f99
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java
@@ -0,0 +1,93 @@
+package org.apache.blur.thrift;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+
+import org.apache.blur.thrift.generated.Field;
+import org.apache.blur.thrift.generated.TYPE;
+
+@SuppressWarnings("serial")
+public class TextField extends Field {
+
+  private static final String UTF_8 = "UTF-8";
+  
+  public TextField(String name, String value) {
+    super(name, toByteBuffer(value), TYPE.TEXT, 1.0);
+  }
+
+  private static ByteBuffer toByteBuffer(String value) {
+    try {
+      return ByteBuffer.wrap(value.getBytes(UTF_8));
+    } catch (UnsupportedEncodingException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public TextField() {
+
+  }
+
+  public TextField(Field field) {
+    super(field.name, field.value, field.type, field.boost);
+    if (field.getType() != TYPE.TEXT) {
+      throw new RuntimeException("Field [" + field + "] is not of type TEXT.");
+    }
+  }
+
+  public String getValueString() {
+    try {
+      return new String(getValue(), UTF_8);
+    } catch (UnsupportedEncodingException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public TextField setValueString(String value) {
+    try {
+      setValue(value.getBytes(UTF_8));
+    } catch (UnsupportedEncodingException e) {
+      throw new RuntimeException(e);
+    }
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("TextField(");
+    boolean first = true;
+
+    sb.append("name:");
+    if (this.name == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.name);
+    }
+    first = false;
+    if (!first)
+      sb.append(", ");
+    sb.append("value:");
+    if (this.value == null) {
+      sb.append("null");
+    } else {
+      sb.append(getValueString());
+    }
+    first = false;
+    if (!first)
+      sb.append(", ");
+    sb.append("type:");
+    if (this.type == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.type);
+    }
+    first = false;
+    if (!first)
+      sb.append(", ");
+    sb.append("boost:");
+    sb.append(this.boost);
+    first = false;
+    sb.append(")");
+    return sb.toString();
+  }
+
+}


Mime
View raw message