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 shell updates, looks pretty good now.
Date Thu, 13 Jun 2013 01:22:08 GMT
Updated Branches:
  refs/heads/master 1bf69537c -> ab468c7f8


More shell updates, looks pretty good now.


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

Branch: refs/heads/master
Commit: ab468c7f88c60a9905ec09b73f0af5915d7e5338
Parents: 1bf6953
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Wed Jun 12 21:21:38 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Wed Jun 12 21:21:38 2013 -0400

----------------------------------------------------------------------
 .../apache/blur/shell/DescribeTableCommand.java | 93 +++++++++++++++++---
 .../org/apache/blur/shell/GetRowCommand.java    | 18 ++--
 .../apache/blur/shell/ListTablesCommand.java    | 10 ++-
 .../org/apache/blur/shell/QueryCommand.java     | 66 ++++++++++++--
 4 files changed, 156 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab468c7f/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java
index 29bdbb7..22437ee 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/DescribeTableCommand.java
@@ -19,35 +19,100 @@
 package org.apache.blur.shell;
 
 import java.io.PrintWriter;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.AlternateColumnDefinition;
+import org.apache.blur.thrift.generated.AnalyzerDefinition;
 import org.apache.blur.thrift.generated.Blur;
 import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.ColumnDefinition;
+import org.apache.blur.thrift.generated.ColumnFamilyDefinition;
 import org.apache.blur.thrift.generated.TableDescriptor;
 
 public class DescribeTableCommand extends Command {
   @Override
-  public void doit(PrintWriter out, Blur.Iface client, String[] args)
-      throws CommandException, TException, BlurException {
+  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException {
     if (args.length != 2) {
       throw new CommandException("Invalid args: " + help());
     }
     String tablename = args[1];
 
     TableDescriptor describe = client.describe(tablename);
-    out.println("cluster               : "+ describe.cluster);
-    out.println("name                  : "+ describe.name);
-    out.println("enabled               : "+ describe.isEnabled);
-    out.println("tableUri              : "+ describe.tableUri);
-    out.println("shardCount            : "+ describe.shardCount);
-    out.println("readOnly              : "+ describe.readOnly);
-    out.println("columnPreCache        : "+ describe.columnPreCache);
+    out.println("cluster               : " + describe.cluster);
+    out.println("name                  : " + describe.name);
+    out.println("enabled               : " + describe.isEnabled);
+    out.println("tableUri              : " + describe.tableUri);
+    out.println("shardCount            : " + describe.shardCount);
+    out.println("readOnly              : " + describe.readOnly);
+    out.println("columnPreCache        : " + describe.columnPreCache);
     out.println(" - Other Options -");
-    //@TODO needs improvement
-    out.println("analyzerDefinition    : "+ describe.analyzerDefinition);
-    out.println("blockCaching          : "+ describe.blockCaching);
-    out.println("blockCachingFileTypes : "+ describe.blockCachingFileTypes);
-    out.println("tableProperties       : "+ describe.tableProperties);
+
+    out.println("blockCaching          : " + describe.blockCaching);
+    out.println("blockCachingFileTypes : " + describe.blockCachingFileTypes);
+    out.println("tableProperties       : " + describe.tableProperties);
+
+    out.println(" - Analyzer Definition -");
+    print(0, out, describe.getAnalyzerDefinition());
+  }
+
+  private void print(int indent, PrintWriter out, AnalyzerDefinition analyzerDefinition)
{
+    ColumnDefinition defaultDefinition = analyzerDefinition.getDefaultDefinition();
+    indent(out, indent).println("defaultDefinition: ");
+    print(indent + 1, out, defaultDefinition);
+    String fullTextAnalyzerClassName = analyzerDefinition.getFullTextAnalyzerClassName();
+    indent(out, indent).println("fullTextAnalyzerClassName: " + fullTextAnalyzerClassName);
+    Map<String, ColumnFamilyDefinition> columnFamilyDefinitions = analyzerDefinition.getColumnFamilyDefinitions();
+    if (columnFamilyDefinitions != null) {
+      indent(out, indent).println("columnFamilyDefinitions: ");
+      for (Entry<String, ColumnFamilyDefinition> colFamDef : columnFamilyDefinitions.entrySet())
{
+        String family = colFamDef.getKey();
+        indent(out, indent + 1).println("family: " + family);
+        ColumnFamilyDefinition value = colFamDef.getValue();
+        print(indent + 2, out, value);
+      }
+    }
+  }
+
+  private PrintWriter indent(PrintWriter out, int indent) {
+    for (int i = 0; i < indent; i++) {
+      out.print("  ");
+    }
+    return out;
+  }
+
+  private void print(int indent, PrintWriter out, ColumnDefinition columnDefinition) {
+    String analyzerClassName = columnDefinition.getAnalyzerClassName();
+    indent(out, indent).println("analyzerClassName: " + analyzerClassName);
+    Map<String, AlternateColumnDefinition> alternateColumnDefinitions = columnDefinition
+        .getAlternateColumnDefinitions();
+    if (alternateColumnDefinitions != null) {
+      indent(out, indent).println("alternateColumnDefinitions: ");
+      for (Entry<String, AlternateColumnDefinition> e : alternateColumnDefinitions.entrySet())
{
+        indent(out, indent + 1).println("alternateDefName: " + e.getKey());
+        AlternateColumnDefinition alternateColumnDefinition = e.getValue();
+        indent(out, indent + 1).println("analyzerClassName: " + alternateColumnDefinition.getAnalyzerClassName());
+      }
+    }
+
+  }
+
+  private void print(int indent, PrintWriter out, ColumnFamilyDefinition value) {
+    ColumnDefinition defaultDefinition = value.getDefaultDefinition();
+    indent(out, indent).println("defaultDefinition: ");
+    print(indent + 1, out, defaultDefinition);
+    Map<String, ColumnDefinition> columnDefinitions = value.getColumnDefinitions();
+    if (columnDefinitions != null) {
+      indent(out, indent).println("columnDefinitions: ");
+      for (Entry<String, ColumnDefinition> e : columnDefinitions.entrySet()) {
+        String column = e.getKey();
+        indent(out, indent + 1).println("column: " + column);
+        ColumnDefinition columnDefinition = e.getValue();
+        indent(out, indent + 1).println("columnDefinition: " + columnDefinition);
+      }
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab468c7f/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java
index eab34a0..da601f8 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/GetRowCommand.java
@@ -67,30 +67,32 @@ public class GetRowCommand extends Command {
     format(out, row, maxWidth);
   }
 
-  private void format(PrintWriter out, Row row, int maxWidth) {
+  public static void format(PrintWriter out, Row row, int maxWidth) {
     String id = row.getId();
     int recordCount = row.getRecordCount();
-    out.println("id:" + id);
-    out.println("recordCount:" + recordCount);
+    out.println("       id : " + id);
+    if (Main.debug) {
+      out.println("recordCount : " + recordCount);
+    }
     List<Record> records = row.getRecords();
     for (Record record : records) {
       format(out, record, maxWidth);
     }
   }
 
-  private void format(PrintWriter out, Record record, int maxWidth) {
+  public static void format(PrintWriter out, Record record, int maxWidth) {
     String recordId = record.getRecordId();
     String family = record.getFamily();
     List<Column> columns = record.getColumns();
-    out.println(" recordId:" + recordId);
-    out.println("   family:" + family);
+    out.println(" recordId : " + recordId);
+    out.println("   family : " + family);
     for (Column column : columns) {
       format(out, column, maxWidth);
     }
   }
 
-  private void format(PrintWriter out, Column column, int maxWidth) {
-    String lead = "     " + column.getName() + ":";
+  private static void format(PrintWriter out, Column column, int maxWidth) {
+    String lead = "     " + column.getName() + " : ";
     String value = column.getValue();
     int length = value.length();
     int position = 0;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab468c7f/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java
index ef418e6..26d2842 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/ListTablesCommand.java
@@ -19,6 +19,7 @@
 package org.apache.blur.shell;
 
 import java.io.PrintWriter;
+import java.util.List;
 
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.generated.Blur;
@@ -26,9 +27,12 @@ import org.apache.blur.thrift.generated.BlurException;
 
 public class ListTablesCommand extends Command {
   @Override
-  public void doit(PrintWriter out, Blur.Iface client, String[] args)
-      throws CommandException, TException, BlurException {
-    out.println("tables: " + client.tableList());
+  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException {
+    List<String> tableList = client.tableList();
+    for (String s : tableList) {
+      out.println(s);
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab468c7f/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
index 0e98a20..28fe909 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
@@ -20,19 +20,25 @@ package org.apache.blur.shell;
 
 import java.io.PrintWriter;
 
+import jline.Terminal;
+import jline.console.ConsoleReader;
+
 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.BlurQuery;
 import org.apache.blur.thrift.generated.BlurResult;
 import org.apache.blur.thrift.generated.BlurResults;
+import org.apache.blur.thrift.generated.FetchResult;
+import org.apache.blur.thrift.generated.FetchRowResult;
+import org.apache.blur.thrift.generated.Row;
 import org.apache.blur.thrift.generated.Selector;
 import org.apache.blur.thrift.generated.SimpleQuery;
 
 public class QueryCommand extends Command {
   @Override
-  public void doit(PrintWriter out, Blur.Iface client, String[] args)
-      throws CommandException, TException, BlurException {
+  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException {
     if (args.length < 3) {
       throw new CommandException("Invalid args: " + help());
     }
@@ -52,14 +58,62 @@ public class QueryCommand extends Command {
       out.println(blurQuery);
     }
 
+    int maxWidth = 100;
+    ConsoleReader reader = getConsoleReader();
+    if (reader != null) {
+      Terminal terminal = reader.getTerminal();
+      maxWidth = terminal.getWidth() - 15;
+    }
+    long s = System.nanoTime();
     BlurResults blurResults = client.query(tablename, blurQuery);
+    long e = System.nanoTime();
+    long timeInNanos = e - s;
 
-    if (Main.debug) {
-      out.println("shardinfo: " + blurResults.getShardInfo());
+    printSummary(out, blurResults, maxWidth, timeInNanos);
+    lineBreak(out, maxWidth);
+    
+    int hit = 0;
+    for (BlurResult result : blurResults.getResults()) {
+      double score = result.getScore();
+      out.println("      hit : " + hit);
+      out.println("    score : " + score);
+      if (Main.debug) {
+        String locationId = result.getLocationId();
+        out.println("locationId : " + locationId);
+      }
+      FetchResult fetchResult = result.getFetchResult();
+      if (Main.debug) {
+        out.println("deleted : " + fetchResult.isDeleted());
+        out.println("exists  : " + fetchResult.isExists());
+        out.println("table   : " + fetchResult.getTable());
+      }
+      FetchRowResult rowResult = fetchResult.getRowResult();
+      if (rowResult != null) {
+        Row row = rowResult.getRow();
+        if (row != null) {
+          GetRowCommand.format(out, row, maxWidth);
+        }
+      }
+      lineBreak(out, maxWidth);
+      hit++;
+    }
+    printSummary(out, blurResults, maxWidth, timeInNanos);
+  }
+
+  private void lineBreak(PrintWriter out, int maxWidth) {
+    for (int i = 0; i < maxWidth; i++) {
+      out.print('-');
     }
+    out.println();
+  }
 
-    for (BlurResult result : blurResults.getResults()) {
-      out.println(result);
+  private void printSummary(PrintWriter out, BlurResults blurResults, int maxWidth, long
timeInNanos) {
+    long totalResults = blurResults.getTotalResults();
+    out.println(" - Results Summary -");
+    out.println("    total : " + totalResults);
+    out.println("    time  : " + (timeInNanos / 1000000.0) + " ms");
+    if (Main.debug) {
+      out.println("shardinfo: " + blurResults.getShardInfo());
     }
   }
 


Mime
View raw message