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

Installing And Exploring Auto Dark Mode Software

Windows Auto--Night--Mode: Simplify Your Theme Switching   Windows Auto--Night--Mode is a free and lightweight tool that makes switching bet...