Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase >> mail # user >> delete rows from hbase


Copy link to this message
-
Re: delete rows from hbase
Oleg,

  Here is some code that we used for deleting all rows with user name
foo.  It should be fairly portable to your situation:

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;

public class HBaseDelete {
public static void main(String[] args){
Configuration conf = HbaseConfiguration.create();
Htable t = new HTable("t");

String user = "foo";

byte[] startRow = Bytes.toBytes(user);
byte[] stopRow = Bytes.toBytes(user);
stopRow[stopRow.length - 1]++; //'fop'
Scan scan = new Scan(start Row, stopRow);
ResultScanner sc = t.getScanner(scan);
for(Result r : sc) {
  t.delete(new Delete(r.getRow()));
}
}
}
/**
 * Start row: foo
 * HBase begins matching this byte, one after another.
 * End row: foo
 * HBase stops matching at first match, cause start == stop.
 * End Row: fo[p] (p being 0 +1)
 * HBase stops matching at something not "foo"
 */
On Tue, Jun 19, 2012 at 6:46 AM, Mohammad Tariq <[EMAIL PROTECTED]> wrote:
> you can use Hbase RowFilter to do that.
>
> Regards,
>     Mohammad Tariq
>
>
> On Tue, Jun 19, 2012 at 1:13 PM, shashwat shriparv
> <[EMAIL PROTECTED]> wrote:
>> Try to impliment something like this
>>
>> Class RegexStringComparator
>>
>>
>>
>> On Tue, Jun 19, 2012 at 5:06 AM, Amitanand Aiyer <[EMAIL PROTECTED]> wrote:
>>
>>> You could set up a scan with the criteria you want (start row, end row,
>>> keyonlyfilter etc), and do a delete for
>>> The rows you get.
>>>
>>> On 6/18/12 3:08 PM, "Oleg Ruchovets" <[EMAIL PROTECTED]> wrote:
>>>
>>> >Hi ,
>>> >I need to delete rows from hbase table by criteria.
>>> >For example I need to delete all rows started with "12345".
>>> >I didn't find a way to set a row prefix for delete operation.
>>> >What is the best way ( practice ) to delete  rows by criteria from hbase
>>> >table?
>>> >
>>> >Thanks in advance.
>>> >Oleg.
>>>
>>>
>>
>>
>> --
>>
>>
>> ∞
>> Shashwat Shriparv

--
Kevin O'Dell
Customer Operations Engineer, Cloudera
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB