More improvements to the shell, needed for documentation examples.
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/92b9326c Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/92b9326c Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/92b9326c Branch: refs/heads/master Commit: 92b9326c80d42c3a0a2a7ece228114e9af13c97e Parents: b08249c Author: Aaron McCurry <[email protected]> Authored: Tue Jun 11 16:42:27 2013 -0400 Committer: Aaron McCurry <[email protected]> Committed: Tue Jun 11 16:42:27 2013 -0400 ---------------------------------------------------------------------- .../org/apache/blur/shell/DeleteRowCommand.java | 51 ++++++++++++++ .../apache/blur/shell/DescribeTableCommand.java | 16 ++++- .../org/apache/blur/shell/GetRowCommand.java | 2 +- .../main/java/org/apache/blur/shell/Main.java | 71 ++++++++++++++++++-- .../apache/blur/shell/SchemaTableCommand.java | 18 ++++- 5 files changed, 146 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/92b9326c/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java new file mode 100644 index 0000000..2267093 --- /dev/null +++ b/blur-shell/src/main/java/org/apache/blur/shell/DeleteRowCommand.java @@ -0,0 +1,51 @@ +package org.apache.blur.shell; + +/** + * 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. + */ +import java.io.PrintWriter; + +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.RowMutation; +import org.apache.blur.thrift.generated.RowMutationType; + +public class DeleteRowCommand extends Command { + + @Override + public void doit(PrintWriter out, Blur.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]; + + RowMutation mutation = new RowMutation(); + mutation.setRowId(rowId); + mutation.setTable(tablename); + mutation.setRowMutationType(RowMutationType.DELETE_ROW); + client.mutate(mutation); + } + + @Override + public String help() { + return "delete the specified row, args; tablename rowid"; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/92b9326c/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 32e563f..29bdbb7 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 @@ -23,6 +23,7 @@ import java.io.PrintWriter; 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; public class DescribeTableCommand extends Command { @Override @@ -33,7 +34,20 @@ public class DescribeTableCommand extends Command { } String tablename = args[1]; - out.println(client.describe(tablename)); + 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(" - 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); } @Override http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/92b9326c/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 bf8be51..213b7c4 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 @@ -55,6 +55,6 @@ public class GetRowCommand extends Command { @Override public String help() { - return "display the specified row, args; tablename query"; + return "display the specified row, args; tablename rowid"; } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/92b9326c/blur-shell/src/main/java/org/apache/blur/shell/Main.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/Main.java b/blur-shell/src/main/java/org/apache/blur/shell/Main.java index d97472f..5759109 100644 --- a/blur-shell/src/main/java/org/apache/blur/shell/Main.java +++ b/blur-shell/src/main/java/org/apache/blur/shell/Main.java @@ -27,6 +27,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; import java.util.concurrent.TimeUnit; import jline.console.ConsoleReader; @@ -101,9 +103,63 @@ public class Main { public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException, TException, BlurException { out.println("Available commands:"); - for (Entry<String, Command> e : commands.entrySet()) { - out.println(" " + e.getKey() + " - " + e.getValue().help()); + + Map<String, Command> cmds = new TreeMap<String, Command>(commands); + + int bufferLength = getMaxCommandLength(cmds.keySet()) + 2; + out.println(" - Table commands - "); + String[] tableCommands = { "create", "enable", "disable", "remove", "describe", "list", "schema", "stats", + "layout" }; + printCommandAndHelp(out, cmds, tableCommands, bufferLength); + + out.println(); + out.println(" - Data commands - "); + String[] dataCommands = { "query", "get", "mutate", "delete" }; + printCommandAndHelp(out, cmds, dataCommands, bufferLength); + + out.println(); + out.println(" - Cluster commands - "); + String[] clusterCommands = { "controllers", "shards", "clusterlist" }; + printCommandAndHelp(out, cmds, clusterCommands, bufferLength); + + out.println(); + out.println(" - Shell commands - "); + String[] shellCommands = { "help", "debug", "timed", "quit" }; + printCommandAndHelp(out, cmds, shellCommands, bufferLength); + + if (!cmds.isEmpty()) { + out.println(); + out.println(" - Other operations - "); + + for (Entry<String, Command> e : cmds.entrySet()) { + out.println(" " + buffer(e.getKey(), bufferLength) + " - " + e.getValue().help()); + } + } + } + + private int getMaxCommandLength(Set<String> keySet) { + int result = 0; + for (String s : keySet) { + if (s.length() > result) { + result = s.length(); + } + } + return result; + } + + private void printCommandAndHelp(PrintWriter out, Map<String, Command> cmds, String[] tableCommands, + int bufferLength) { + for (String c : tableCommands) { + Command command = cmds.remove(c); + out.println(" " + buffer(c, bufferLength) + " - " + command.help()); + } + } + + private String buffer(String s, int bufferLength) { + while (s.length() < bufferLength) { + s = s + " "; } + return s; } @Override @@ -144,14 +200,15 @@ public class Main { builder.put("disable", new EnableDisableTableCommand()); builder.put("remove", new RemoveTableCommand()); builder.put("describe", new DescribeTableCommand()); - builder.put("tablestats", new TableStatsCommand()); + builder.put("stats", new TableStatsCommand()); builder.put("schema", new SchemaTableCommand()); builder.put("query", new QueryCommand()); - builder.put("getrow", new GetRowCommand()); - builder.put("mutaterow", new MutateRowCommand()); + builder.put("get", new GetRowCommand()); + builder.put("delete", new DeleteRowCommand()); + builder.put("mutate", new MutateRowCommand()); builder.put("indexaccesslog", new IndexAccessLogCommand()); - builder.put("shardclusterlist", new ShardClusterListCommand()); - builder.put("shardserverlayout", new ShardServerLayoutCommand()); + builder.put("clusterlist", new ShardClusterListCommand()); + builder.put("layout", new ShardServerLayoutCommand()); builder.put("controllers", new ControllersEchoCommand()); builder.put("shards", new ShardsEchoCommand()); commands = builder.build(); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/92b9326c/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java index b8421a0..3fa82eb 100644 --- a/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java +++ b/blur-shell/src/main/java/org/apache/blur/shell/SchemaTableCommand.java @@ -19,21 +19,33 @@ package org.apache.blur.shell; import java.io.PrintWriter; +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.Schema; public class SchemaTableCommand 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]; - out.println(client.schema(tablename)); + Schema schema = client.schema(tablename); + out.println(schema.getTable()); + Map<String, Set<String>> columnFamilies = schema.getColumnFamilies(); + for (String cf : columnFamilies.keySet()) { + out.println("family : " + cf); + Set<String> columns = columnFamilies.get(cf); + for (String c : columns) { + out.println("\tcolumn : " + c); + } + } } @Override
