From 5b347e26e91c922ef9729bf59d4a1274de0b5136 Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Wed, 18 Jan 2012 10:22:15 +0100 Subject: [PATCH] Adding EXERCISES.md to match hbase shell exercises from HBase book (Stack proposal). Also begin implementing 'create' command. CTRL-D is now handled properly, hope so. --- EXERCISES.md | 11 +++++++++++ bin/hubris | 2 +- project.clj | 2 +- src/hubris/builtin.clj | 20 +++++++++++++++++--- src/hubris/repl.clj | 5 +++++ 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 EXERCISES.md diff --git a/EXERCISES.md b/EXERCISES.md new file mode 100644 index 0000000..94d9f87 --- /dev/null +++ b/EXERCISES.md @@ -0,0 +1,11 @@ +# Shell Exercises + +This article is inspired from [HBase Book Exercises](http://hbase.apache.org/book/quickstart.html#shell_exercises). + +Connect to your running HBase via **hubris**. + + $ ./bin/hubris + Hbase UBer Interactive Shell; enter 'help' to see available commands or 'exit' to quit. + hubris> + +Type **help** diff --git a/bin/hubris b/bin/hubris index fe61e74..feaf567 100755 --- a/bin/hubris +++ b/bin/hubris @@ -1,6 +1,6 @@ #!/bin/sh -VERSION="0.1.0" +VERSION="0.2.0" # content location program=`basename $0` diff --git a/project.clj b/project.clj index d529a65..88d743b 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject hubris "0.1.0" +(defproject hubris "0.2.0" :description "Hubris - HBase uber shell" :license "EPL 1.0" :url "http://github.com/sanel/hubris" diff --git a/src/hubris/builtin.clj b/src/hubris/builtin.clj index b4fd32d..fcc122b 100644 --- a/src/hubris/builtin.clj +++ b/src/hubris/builtin.clj @@ -56,9 +56,9 @@ Examples: hubris> connect ;; connect to localhost hubris> connect \"foo\" ;; connect to 'foo' host and the same zookeeper address hubris> connect \"foo\" \"baz\" ;; connect to 'foo' host with 'baz' as zookeeper address" - ([] (connect "localhost")) - ([host] (connect host host)) - ([host zk] (hbase.core/connect-to host zk)) + ([] (connect "localhost")) + ([host] (connect host host)) + ([host zk] (hbase.core/connect-to host zk)) ) (defcommand host @@ -70,6 +70,20 @@ Examples: (println "Not connected to any HBase instance") ) ) ) + (defcommand create + "Create table; pass table name, a dictionary of specifications per column family, and optionally +a dictionary of table configuration. Dictionaries are described below in the GENERAL NOTES section. + +Examples: + + hbase> create \"t1\" {:NAME \"f1\" :VERSIONS 5} + hbase> create \"t1\" [{:NAME \"f1\"} {:NAME \"f2\"} {:NAME \"f3\"}] + hbase> ;; The above in shorthand would be the following: + hbase> create \"t1\" \"f1\" \"f2\" \"f3\" + hbase> create \"t1\" {:NAME \"f1\" :VERSIONS 1 :TTL 2592000 :BLOCKCACHE true}" + [table opts] + (println "TODO")) + (defcommand list-tables "List all tables in hbase" [] diff --git a/src/hubris/repl.clj b/src/hubris/repl.clj index 3a281de..1d4a9e7 100644 --- a/src/hubris/repl.clj +++ b/src/hubris/repl.clj @@ -38,6 +38,11 @@ (defn evaluate-with-redirection "Scan expression for possible redirection(s), and if found, bind output to it. If not, proceed as usual." [expr] + ;; Try to catch CTRL-D input; normaly, REPL would quit with CTRL-C, but CTRL-D combo would force nil input + ;; causing further functions to throw null exception. I'm hoping this 'hack' would not cause other troubles... + (when-not expr + (System/exit 0)) + (if (re-find #"\s+>\s+" expr) (do (let [tokens (.split expr "\\s+>\\s+")