Monday, August 25, 2014

HBase : Unix/Shell Script File for Creating,Putting/Disabling/Droping tables and Inserting bulk load of datasets from Hadoop HDFS

#!/bin/bash

# Declaring Variables
table0="employee"

path=$(pwd);

# Creating a Employee table in HBase

echo "exists '$table0'" | hbase shell > log
cat log | grep "Table employee does exist"
if [ $? = 0 ];then
    echo "************  table is already exists **********"

# Either you can use truncate or disable & drop options

    echo "disable '$table0'" | hbase shell
    echo "drop '$table0'" | hbase shell
#  echo "truncate '$table0'" | hbase shell
    echo "create '$table0','count'" | hbase shell

# Either you can use shell commands here or call another .sh file.. here i have used another file option

cd $path/depends
chmod +x hbase-script.sh
  ./hbase-script.sh | hbase shell
else
    echo "***********  need to create a table  **********"
    echo "create '$table0','count'" | hbase shell
cd $path/depends
chmod +x hbase-script.sh
./hbase-script.sh | hbase shell
fi

# Creating, copying and populating the table0 table

echo ${HADOOP_HOME}
username="$USER"

echo $(hadoop fs -copyFromLocal $path/depends/table0 /user/$username/hbasetable/table0)
echo $(hbase org.apache.hadoop.hbase.mapreduce.Import table0 /user/$username/hbasetable/table0)
echo $(hadoop fs -rmr /user/$username/hbasetable)
exit

12 comments:

  1. Hi,

    Is there a way to execute the hbase commands like we do for hive. for eg. in hive we do
    hive -e "select a,b,c from abc;"

    Something similar like this. thanks for the help

    ReplyDelete
  2. OnlineITGuru is the top services provider for receiving knowledge on Ruby and they are

    familiar with internet and websites programming like Big data hadoop online Training Bangalore

    ReplyDelete