Recent Posts

Wednesday, 8 March 2017

HBase Update Data Tutorial


Updating Data using HBase Shell
     We can update an existing cell value using the put command. To do so, just follow the same syntax and mention your new value as shown below.
put ‘table name’,’row ’,'Column family:column name',’new value’
     The newly given value replaces the existing value. The following command will update the city value of the employee named ‘Ashok’ to Vijayawada.
hbase> put 'emp','row1','personal:city','Vijayawada'
0 row(s) in 0.0630 seconds
Updating Data Using Java API
package com.ashok.hbase;

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.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class MyInsertData {
   public static void main(String[] args) throws IOException {
      // Instantiating Configuration class
      Configuration config = HBaseConfiguration.create();

      // Instantiating HTable class
      HTable hTable = new HTable(config, "emp");

      // Instantiating Put class
      // accepts a row name.
      Put p = new Put(Bytes.toBytes("row1")); 

      //Updating a cell value
      p.add(Bytes.toBytes("personal"),
      Bytes.toBytes("city"),Bytes.toBytes("Vijayawada"));
  
      // Saving the put Instance to the HTable.
      hTable.put(p);
      System.out.println("Data updated successfully ");
      
      // closing HTable
      hTable.close();
   }
}

Next Tutorial  HBase Read Data Tutorial

Previous Tutorial  HBase Insert Data Tutorial 
 

1 comment: