Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A script that deletes all tables in Hbase

I can tell hbase to disable and delete particular tables using:

disable 'tablename'
drop 'tablename'

But I want to delete all the tables in the database without hardcoding the names of any of the tables. Is there a way to do this? I want to do this through the command-line utility ./hbase shell, not through Java or Thrift.

like image 282
Vlad the Impala Avatar asked Oct 21 '10 19:10

Vlad the Impala


3 Answers

disable_all and drop_all have been added as commands in the HBase ruby shell. These commands were added in jira HBASE-3506 These commands take a regex of tables to disable/drop. And they will ask for confirmation before continuing. That should make droping lots of tables pretty easy and not require outside libraries or scripting.

like image 138
eclark Avatar answered Oct 13 '22 14:10

eclark


I have a handy script that does exactly this, using the Python Happybase library:

import happybase

c = happybase.Connection()

for table in c.tables():
  c.disable_table(table)
  c.delete_table(table)
  print "Deleted: " + table

You will need Happybase installed to use this script, and you can install it as:

sudo easy_install happybase
like image 23
Suman Avatar answered Oct 13 '22 16:10

Suman


You can pipe commands to the bin/hbase shell command. From there you can use some scripting to grab the table names and pipe the disable/delete commands back to hbase.

i.e.

echo "list" | bin/hbase shell | ./filter_table_names.pl > table_names.txt
./turn_table_names_into_disable_delete_commands.pl table_names.txt | bin/hbase shell 
like image 34
bajafresh4life Avatar answered Oct 13 '22 16:10

bajafresh4life