How to clear a table in hbase?

Using hbase shell, truncate <table_name> will do the task.

The snapshot of truncate 'customer_details' command is shown below:enter image description here

where customer_details is the table name


Another efficient option is to actually delete the table then reconstruct another one with all the same settings as the previous.

I don't know how to do this in php, but I do know how to do it in Java. The corresponding actions in php should be similar, you just need to check how the API looks like.

In Java using HBase 0.90.4:

// Remember the "schema" of your table
HBaseAdmin admin = new HBaseAdmin(yourConfiguration);
HTableDescriptor td = admin.getTableDescriptor(Bytes.toBytes("yourTableName");

// Delete your table
admin.disableTable("yourTableName");
admin.deleteTable("yourTableName");

// Recreate your talbe
admin.createTable(td);

If you execute this in HBase shell:

 > truncate 'yourTableName'

Then HBase will execute this operations for 'yourTableName':

 > disable 'yourTableName'
 > drop 'yourTableName'
 > create 'yourTableName', 'f1', 'f2', 'f3'

Tags:

Php

Hbase