Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a table in hbase?

Tags:

php

hbase

I want to empty a table in hbase... eg: user. Is there any command or function to empty the table without deleting it...

My table structure is :

$mutations = array(
                new Mutation( array(
                    'column' => 'username:1',
                    'value' =>$name
                ) ),
                new Mutation( array(
                    'column' => 'email:1',
                    'value' =>$email
                ) )
        );          
$hbase->mutateRow("user",$key,$mutations);

Can someone help me?

like image 412
Micku Avatar asked Mar 28 '12 06:03

Micku


2 Answers

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'
like image 102
Alexis Gamarra Avatar answered Sep 17 '22 17:09

Alexis Gamarra


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);
like image 25
André Staltz Avatar answered Sep 18 '22 17:09

André Staltz