Dear Wiki user, You have subscribed to a wiki page or wiki category on "Hadoop Wiki" for change notification.
The "Hbase/Shell" page has been changed by stack. http://wiki.apache.org/hadoop/Hbase/Shell?action=diff&rev1=11&rev2=12 -------------------------------------------------- The ''hirb.rb' script defines a set of hbase methods (get, set, scan, etc.), sets some environment variables, imports a few hbase-particular modules -- a results Formatter and a ruby wrapper around the ''HBaseAdmin'' and ''HTable'' java classes that can be found at ''${HBASE_HOME}/bin/HBase.rb'' -- and then starts up a subclass of IRB, named HIRB (IRB is the name of the interactive Ruby interpreter; for an untainted irb experience, type 'irb' on a system that has ruby installed). The subclassing is done to alter slightly some of the usual IRB behaviors. For instance, every command invocation returns a result and the result is printed to the terminal even if the result is nil. The subclass intercepts nil emissions and just suppresses them. '' - ''Anything you can do in irb, or at least in its JRuby equivalent, ''jirb'', you should be able to do in HBase Shell. '' + Anything you can do in irb, or at least in its JRuby equivalent, ''jirb'', you should be able to do in HBase Shell. == Scripting == - ''You can pass scripts to the HBase Shell by doing the following: '' + You can pass scripts to the HBase Shell by doing the following: + {{{ - ''{{{durruti:~ stack$ ${HBASE_HOME}/bin/hbase shell PATH_TO_SCRIPT}}} '' + durruti:~ stack$ ${HBASE_HOME}/bin/hbase shell PATH_TO_SCRIPT + }}} - ''Your script can lean on the methods provided by the HBase Shell. '' + Your script can lean on the methods provided by the HBase Shell. - ''For more control, you may prefer manipulating HTable and HBaseAdmin methods directly. For example, if you would do your own formatting or you are storing structures that are mangled when manipulated in HBase Shell. In this case, you might pass your scripts directly to JRuby by doing: '' + For more control, you may prefer manipulating HTable and HBaseAdmin methods directly. For example, if you would do your own formatting or you are storing structures that are mangled when manipulated in HBase Shell. In this case, you might pass your scripts directly to JRuby by doing: + {{{ - ''{{{durruti:~ stack$ ${HBASE_HOME}/bin/hbase org.jruby.Main PATH_TO_SCRIPT}}} '' + durruti:~ stack$ ${HBASE_HOME}/bin/hbase org.jruby.Main PATH_TO_SCRIPT + }}} - ''For examples writing straight ruby manhandling hbase client instances, see the scripts on this page: [[Hbase/JRuby]] (Ignore the sections that have you fetching the jruby jar and the prefacing your scripts with the '#!' bang magic). '' + For examples writing straight ruby manhandling hbase client instances, see the scripts on this page: [[Hbase/JRuby]] (Ignore the sections that have you fetching the jruby jar and the prefacing your scripts with the '#!' bang magic). == Useful Tricks == === irbrc === - ''Create an ''.irbrc'' file for yourself in your home directory. Add HBase Shell customizations. A useful one is command history: '' + Create an ''.irbrc'' file for yourself in your home directory. Add HBase Shell customizations. A useful one is command history: - ''{{{durruti:~ stack$ more .irbrc require 'irb/ext/save-history' IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"}}} '' + {{{ + durruti:~ stack$ more .irbrc + require 'irb/ext/save-history' + IRB.conf[:SAVE_HISTORY] = 100 + IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" + }}} === Log date to timestamp === - ''To convert the date '08/08/16 20:56:29' from an hbase log into a timestamp, do: {{{hbase(main):021:0> import java.text.SimpleDateFormat hbase(main):022:0> import java.text.ParsePosition hbase(main):023:0> SimpleDateFormat.new("yy/MM/dd HH:mm:ss").parse("08/08/16 20:56:29", ParsePosition.new(0)).getTime() => 1218920189000}}} '' + To convert the date '08/08/16 20:56:29' from an hbase log into a timestamp, do: {{{ + hbase(main):021:0> import java.text.SimpleDateFormat + hbase(main):022:0> import java.text.ParsePosition + hbase(main):023:0> SimpleDateFormat.new("yy/MM/dd HH:mm:ss").parse("08/08/16 20:56:29", ParsePosition.new(0)).getTime() => 1218920189000 + }}} - ''To go the other direction, do: {{{hbase(main):021:0> import java.util.Date hbase(main):022:0> Date.new(1218920189000).toString() => "Sat Aug 16 20:56:29 UTC 2008"}}} '' + To go the other direction, do: {{{ + hbase(main):021:0> import java.util.Date + hbase(main):022:0> Date.new(1218920189000).toString() => "Sat Aug 16 20:56:29 UTC 2008" + }}} - ''To output in a format that is exactly like hbase log format is a pain messing with SimpleDateFormat. '' + To output in a format that is exactly like hbase log format is a pain messing with SimpleDateFormat.
