In this tutorial, we will see usage, syntax, and examples of how to remove an entire row and a specific column cell of a row from an HBase table using delete and deleteall commands.
First, let’s scan the data we are going to run our examples on.
hbase(main):065:0* scan 'emp'
ROW COLUMN+CELL
1 column=office:age, timestamp=1566588721078, value=20
1 column=office:name, timestamp=1566542294972, value=Scott
2 column=office:age, timestamp=1566542472741, value=50
2 column=office:gender, timestamp=1566542429937, value=M
2 column=office:name, timestamp=1566542396815, value=Mark
3 column=office:age, timestamp=1566588693551, value=60
3 column=office:name, timestamp=1566581671205, value=Jeff
3 column=office:salary, timestamp=1566587228604, value=30000
3 row(s)
Using deleteall command
Use deleteall
to remove a specified row from an HBase table. This takes table name and row as a mandatory argument; optionally column and timestamp. It also supports deleting a row range using a row key prefix. The syntax for deleteall
is as follows.
Syntax: deleteall ‘<table_name>’, ‘row_key’, ‘<column_name>’
This removes row 1 and all its cells from a table ’emp’
hbase(main):052:0> deleteall 'emp', '1'
This removes cell ‘office:age’ from row 2
hbase(main):067:0> deleteall 'emp', '2', 'office:age'
Running scan will not fetch removed rows and columns.
hbase(main):068:0> scan 'emp'
ROW COLUMN+CELL
2 column=office:gender, timestamp=1566542429937, value=M
2 column=office:name, timestamp=1566542396815, value=Mark
3 column=office:age, timestamp=1566588693551, value=60
3 column=office:name, timestamp=1566581671205, value=Jeff
3 column=office:salary, timestamp=1566587228604, value=30000
2 row(s)
Using CACHE option, we should able to tell how many batches to send to server at a time, this is mainly used when we are dealing with larget set of the data. When not specified default is 100.
deleteall 'emp', {CACHE => 100}
Some other examples to explore
deleteall 't1', 'r1', 'c1', ts1
hbase> deleteall 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1'
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix', CACHE => 100}
Using delete command
Use delete
command, to remove a column at a row from a table. Let’s see syntax and some examples. Unlike deleteall
, delete command takes ‘column cell’ as a mandatory argument along with table and row key. Optionally it takes timestamp. The
syntax for delete is as follows.
Syntax: delete ‘<table_name>’, ‘row_key’, ‘<column_name>’
Some examples to explore
hbase> delete 't1', 'r1', 'c1', ts1
hbase> delete 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
thank you NNK