You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2008/06/01 07:19:08 UTC

svn commit: r662148 - in /hadoop/hbase/trunk/bin: hbase hirb.rb

Author: stack
Date: Sat May 31 22:19:08 2008
New Revision: 662148

URL: http://svn.apache.org/viewvc?rev=662148&view=rev
Log:
HBASE-487 Replace hql w/ a hbase-friendly jirb or jython shell

Modified:
    hadoop/hbase/trunk/bin/hbase
    hadoop/hbase/trunk/bin/hirb.rb

Modified: hadoop/hbase/trunk/bin/hbase
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/bin/hbase?rev=662148&r1=662147&r2=662148&view=diff
==============================================================================
--- hadoop/hbase/trunk/bin/hbase (original)
+++ hadoop/hbase/trunk/bin/hbase Sat May 31 22:19:08 2008
@@ -183,7 +183,8 @@
 
 # figure out which class to run
 if [ "$COMMAND" = "shell" ] ; then
-  CLASS="org.jruby.Main --command irb -r${HBASE_HOME}/bin/hirb.rb"
+  # CLASS="org.jruby.Main --command irb -r${HBASE_HOME}/bin/hirb.rb"
+  CLASS="org.jruby.Main ${HBASE_HOME}/bin/hirb.rb"
 elif [ "$COMMAND" = "master" ] ; then
   CLASS='org.apache.hadoop.hbase.master.HMaster'
 elif [ "$COMMAND" = "regionserver" ] ; then

Modified: hadoop/hbase/trunk/bin/hirb.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/bin/hirb.rb?rev=662148&r1=662147&r2=662148&view=diff
==============================================================================
--- hadoop/hbase/trunk/bin/hirb.rb (original)
+++ hadoop/hbase/trunk/bin/hirb.rb Sat May 31 22:19:08 2008
@@ -1,13 +1,12 @@
-# Module passed to jirb using the '-r' flag when bin/hbase shell is invoked.
-# Pollutes jirb with hbase imports and hbase commands.  Outputs a banner
-# that tells user where to find help, shell version, etc.
+# Command passed to org.jruby.Main.  Pollutes jirb with hbase imports and hbase
+# commands and then loads jirb.  Outputs a banner that tells user where to find
+# help, shell version, etc.
 
 # TODO: Process command-line arguments: e.g. --master= or -Dhbase.etc and --formatter
 # or read hbase shell configurations from irbrc
 # TODO: Read from environment which outputter to use (outputter should
 # be able to output to a passed Stream as well as STDIN and STDOUT)
 # TODO: Write a base class for formatters with ascii, xhtml, and json subclasses.
-# TODO: Intercept 'help'
 
 # Run the java magic include and import basic HBase types.
 include Java
@@ -22,22 +21,122 @@
 # Some goodies for hirb. Should these be left up to the user's discretion?
 require 'irb/completion'
 
-# Set the irb shell name to be hbase.
-IRB.conf[:IRB_NAME] = "hbase"
-
-def hbase
+def help
   puts 'HBase Shell Commands:'
   puts ' version   Output HBase version'
+  puts ARGV.inspect
 end
 
 def version
-  puts "Version: #{org.apache.hadoop.hbase.util.VersionInfo.getVersion()},\
+  "Version: #{org.apache.hadoop.hbase.util.VersionInfo.getVersion()},\
  r#{org.apache.hadoop.hbase.util.VersionInfo.getRevision()},\
  #{org.apache.hadoop.hbase.util.VersionInfo.getDate()}"
 end
 
+# general
+
+def list
+  puts "Not implemented yet"
+end
+
+# DDL
+
+def create(table_name, *args)
+  puts "Not impemented yet"
+end
+
+def drop(table_name)
+  puts "Not implemented yet"
+end
+
+def alter(table_name, *args)
+  puts "Not implemented yet"
+end
+
+# admin
+  
+def enable(table_name)
+  puts "Not implemented yet"
+end
+
+def disable(table_name)
+  puts "Not implemented yet"
+end
+  
+def truncate(table_name)
+  puts "Not implemented yet"
+end
+
+# CRUD
+  
+def get(table_name, row_key, *args)
+  puts "Not implemented yet"
+end
+
+def put(table_name, row_key, *args)
+  puts "Not implemented yet"
+end
+  
+def scan(table_name, start_key, end_key, *args)
+  puts "Not implemented yet"
+end
+  
+def delete(table_name, row_key, *args)
+  puts "Not implemented yet"
+end
+
+
+
 # Output a banner message that tells users where to go for help
 # TODO: Test that we're in irb context.  For now presume it.
 # TODO: Test that we are in shell context.
 puts "HBase Shell; type 'hbase<RETURN>' for the list of supported HBase commands"
-version
+puts version
+
+require "irb"
+
+IRB::ExtendCommandBundle.instance_variable_get("@EXTEND_COMMANDS").delete_if{|x| x.first == :irb_help}
+
+module IRB
+  module ExtendCommandBundle
+    
+  end
+  
+  def IRB.start(ap_path = nil)
+    $0 = File::basename(ap_path, ".rb") if ap_path
+
+    IRB.setup(ap_path)
+    
+    @CONF[:PROMPT][:HBASE] = {
+      :PROMPT_I => "hbase> ",
+    	:PROMPT_N => "hbase> ",
+    	:PROMPT_S => nil,
+    	:PROMPT_C => "?> ",
+    	:RETURN => "%s\n"
+    }
+    @CONF[:PROMPT_MODE] = :HBASE
+    
+    
+    if @CONF[:SCRIPT]
+      irb = Irb.new(nil, @CONF[:SCRIPT])
+    else
+      irb = Irb.new
+    end
+
+    @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
+    @CONF[:MAIN_CONTEXT] = irb.context
+
+    trap("SIGINT") do
+      irb.signal_handle
+    end
+
+    catch(:IRB_EXIT) do
+      irb.eval_input
+    end
+  end
+end
+
+
+# .delete_if{|x| x.first == :irb_help}.inspect
+
+IRB.start