Tuesday, January 24, 2012

How to delete a specific row or given rows in hbase using java code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package witsml131;

import java.io.IOException;
import java.util.ArrayList;
import javax.security.auth.login.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.Bytes;

/**
 *
 * @author shashwat
 */
public class DeleteFromHbase {

    public static void main(String[] args) throws IOException {

        HTable table = new HTable("well");
        ArrayList<String> rowsToDelete = new ArrayList(); //array with all rows names to delete.
        Delete del = new Delete(Bytes.toBytes("2"));//for single row named 2

        table.delete(del);
      
        //deleting all rows in rowsToDelete in array list rowsToDelete
        for (String rows : rowsToDelete) {
            del = new Delete(Bytes.toBytes(rows));//for single row named 2

            table.delete(del);
        }
        table.close();
    }
}

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Intel #Core #i9 #Processors: A Breakdown

Intel Core i9 Processors: A Breakdown Intel's 14th Gen Core i9 series offers a range of processors designed for various use cases. Her...