HBASE-487 Replace hql w/ a hbase-friendly jirb or jython shell

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@662148 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2008-06-01 05:19:08 +00:00
parent 7e0dd33fb7
commit a3a4fcce15
2 changed files with 111 additions and 11 deletions

View File

@ -183,7 +183,8 @@ unset IFS
# figure out which class to run # figure out which class to run
if [ "$COMMAND" = "shell" ] ; then 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 elif [ "$COMMAND" = "master" ] ; then
CLASS='org.apache.hadoop.hbase.master.HMaster' CLASS='org.apache.hadoop.hbase.master.HMaster'
elif [ "$COMMAND" = "regionserver" ] ; then elif [ "$COMMAND" = "regionserver" ] ; then

View File

@ -1,13 +1,12 @@
# Module passed to jirb using the '-r' flag when bin/hbase shell is invoked. # Command passed to org.jruby.Main. Pollutes jirb with hbase imports and hbase
# Pollutes jirb with hbase imports and hbase commands. Outputs a banner # commands and then loads jirb. Outputs a banner that tells user where to find
# that tells user where to find help, shell version, etc. # help, shell version, etc.
# TODO: Process command-line arguments: e.g. --master= or -Dhbase.etc and --formatter # TODO: Process command-line arguments: e.g. --master= or -Dhbase.etc and --formatter
# or read hbase shell configurations from irbrc # or read hbase shell configurations from irbrc
# TODO: Read from environment which outputter to use (outputter should # TODO: Read from environment which outputter to use (outputter should
# be able to output to a passed Stream as well as STDIN and STDOUT) # 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: 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. # Run the java magic include and import basic HBase types.
include Java include Java
@ -22,22 +21,122 @@ import org.apache.hadoop.hbase.io.BatchUpdate
# Some goodies for hirb. Should these be left up to the user's discretion? # Some goodies for hirb. Should these be left up to the user's discretion?
require 'irb/completion' require 'irb/completion'
# Set the irb shell name to be hbase. def help
IRB.conf[:IRB_NAME] = "hbase"
def hbase
puts 'HBase Shell Commands:' puts 'HBase Shell Commands:'
puts ' version Output HBase version' puts ' version Output HBase version'
puts ARGV.inspect
end end
def version 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()},\ r#{org.apache.hadoop.hbase.util.VersionInfo.getRevision()},\
#{org.apache.hadoop.hbase.util.VersionInfo.getDate()}" #{org.apache.hadoop.hbase.util.VersionInfo.getDate()}"
end 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 # 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're in irb context. For now presume it.
# TODO: Test that we are in shell context. # TODO: Test that we are in shell context.
puts "HBase Shell; type 'hbase<RETURN>' for the list of supported HBase commands" 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