Parth's Blog

© 2021. Parth Patil All rights reserved.

Custom functions in HBase shell

As many of you might know that the HBase shell is a jruby repl. So you can write ruby code in the shell. You can also save your custom ruby functions in ~/.irbrc and the next time you start the hbase shell those functions will be available to you. At work I often need to truncate a bunch of HBase tables before I can begin my testing. I wanted to automate this. So I wrote the following custom function to truncate a list of tables and added it to my ~/.irbrc

def truncate_tables()
  tables = [
    'table1',
    'table2',
    'table3'
  ]

  tables.each {|x| truncate x}
end

You have to restart your HBase shell for this function to be available in the shell. Now this custom function can be invoked from the shell as follows

ruby-1.9.2-p136 :001 > truncate_tables

For more information refer to the following links:

HBase Wiki

Stack Overflow Question

comments powered by Disqus