Hbase interact with shell
Upcoming SlideShare
Loading in...5

Hbase interact with shell






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Hbase interact with shell Hbase interact with shell Presentation Transcript

  • dwivedishashwat@gmail.com
  • LISTList all tables in HBaseSyntax :Htase :> list
  • CREATECreate table;Pass table nameSyntax :Hbase :> creat ‘tablename’,’colFamily’
  • MORE EXAPLEShbase> create tableToBeCreated, {NAME => colFammily1, VERSIONS => 5}hbase> create tableToBeCreated, {NAME => colFammily1}, {NAME => colFammily2}, {NAME => f3}hbase> # The above in shorthand would be the following:hbase> create tableToBeCreated, colFammily1, colFammily2, f3hbase> create tableToBeCreated, {NAME => colFammily1, VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true
  • DESCRIBEDescribe the named table:e.g.hbase> describe table1
  • COUNTCount the number of rows in a table.This operation may take a LONG time (Run $HADOOP_HOME/bin/hadoop jar hbase.jar rowcount to run a counting mapreduce job).Current count is shown every 1000 rows by default.Count interval may be optionally specified.Examples:hbase> count t1 hbase> count t1, 100
  • DELETEPut a delete cell value at specified table/row/column and optionally timestamp coordinates.Eg:Delete ‘table’,’colfam:columnname’
  • DELETEALLDelete all cells in a given row; pass a table name, row, and optionally a column and timestampDelete ‘table’,’rowkey’
  • DISABLEDisable the named table:e.g."hbase> disable t1"
  • DROPDrop the named table. Table must first be disabled.Eg:Drop ‘tablename’
  • ENABLEEnable the named tableEg:Enable ‘tablename’
  • EXISTSDoes the named table exist?e.g."hbase> exists t1"
  • GETGet row or cell contents; pass table name, row,hbase> get t1, r1hbase> get t1, r1, {COLUMN => c1}hbase> get t1, r1, {COLUMN => [c1, c2, c3]}hbase> get t1, r1, {COLUMN => c1, TIMESTAMP => ts1}hbase> get t1, r1, {COLUMN => c1, TIMESTAMP => ts1, VERSIONS => 4}
  • PUTPut a cell value at specified table/row/column and optionally timestamp coordinates.To put a cell value into table t1 at row r1 under column c1do:hbase> put t1, r1, c1, value
  • SCANScan a tableTo scan all members of a column family, leave the qualifier empty as in col_family:.hbase> scan t1’
  • STATUSShow cluster status.Can be summary, simple, or detailed.The default is summary.Examples:hbase> statushbase> status simplehbase> status summaryhbase> status detailed
  • SHUTDOWNShut down the cluster.
  • TRUNCATEDisables, drops and recreates the specified table.
  • VERSIONOutput this HBase version
  • ALTERAlter column family schema; pass table name and a dictionary specifying new column family schema. Dictionaries are described below in the GENERAL NOTES section. Dictionary must include name of column family to alter.For example,To change or add the f1 column family in table t1 from defaults to instead keep a maximum of 5 cell VERSIONS, do:hbase> alter t1, {NAME => f1, VERSIONS => 5}To delete the f1 column family in table t1, do:hbase> alter t1, {NAME => f1, METHOD => delete}
  • EXITTypehbase> exitto leave the HBase Shell
  • SCRIPTINGYou can pass scripts to the HBase Shell by doing the following:bin/hbase shell PATH_TO_SCRIPT
  • SOME HBASE TRICKSecho "create user, info" | hbase shellUsing this command you can create table called use with column family name info without entering to the hbase shell.for i in 0..4 do put "user", "user_#{i}", "info:email", "user_#{i}@hakunamapdata.com" EndThis will create 4 users with user#1 to 4 and put email address too
  • SCRIPT FOR HBASEcat hbase_user_part_scan.txt scan user, {STARTROW => user_1, STOPROW => user_3} exit$ hbase shell hbase_user_part_scan.txtThis script will scan the user table and give output.
  • USING BASH SCRIPT#!/bin/bash TABLE=$1 STARTROW=$2 STOPROW=$3 exec hbase shell <<EOF scan "${TABLE}", {STARTROW => "${STARTROW}", STOPROW => "${STOPROW}"} EOF$ ./part_scan.sh user user_1 user_3
  • SEE WHEN A RECORD WAS ADDEDget user, user_1‘Time.at(1344763701019/1000)Will show you the human understable time likeSun Aug 12 11:28:21 +0200 2012
  • SCHEMA DESIGNWe can take advantage of table schema and store all information realated to a given user in one row (but in two separate column families: info and friend). Last but not least, the rowkey can be simply the user’s unique username.It leads us to the following table schema:Just visit this link for understanding more on schema designing :http://www.slideshare.net/hmisty/20090713-hbase- schema-design-case-studies
  • ADDING MORE DATA TO HBASE TABLES$ hbase shellhbase(main):001:0> create user, info, friendhbase(main):002:0> put user, username1, friend:username2, childhoodhbase(main):003:0> put user, username1, friend:username3, childhoodhbase(main):004:0> put user, username2, friend:username3, childhoodhbase(main):005:0> put user, username2, friend:username4, childhoodhbase(main):006:0> put user, username3, friend:username5, childhoodhbase(main):007:0> put user, username1, friend:username5, childhood‘Or you can write an script to create these value
  • SPECIFYING DIFFERENT CONFIGURATION FOR HBASE SHELLHBase Shell is started by using the hbase shell command. This command uses the HBase configuration file (hbase-site.xml) for the client to find the cluster to connect to. After connecting to the cluster, it starts a prompt, waiting for commands. As shown in the following code, you can also use the -- config option, which allows you to pass a differentconfiguration for HBase Shell to use:hbase --config <configuration_directory> shell
  • SOME HELPFUL COMMANDS : EXERCISEGet a specified row by using the get command:Delete a specified cell by using the delete command:Delete all the cells in a given row using the deleteall command:enable the balancer
  • ANSWERSget t1, row1delete t1, row1, f1:c1‘deleteall t1, row1‘balance_switch true
  • YOU WANT TO QUERY HBASE USING SQL????Use hive to query . For that you need to create a table in hive as external table to hbase as follows:create external table hbase_tablehbase (key string, v01 string, v02 string, v03 string) stored by org.apache.hadoop.hive.hbase.HBaseStorageHandler with serdeproperties ("hbase.columns.mapping" = ":key,n:v01,n:v02,n:v03") tblproperties("hbase.table.name" = "tablehbase");select * from hbase_hly_temp where v01=808C;You can give this query in hive to get data from hbase  and you have lot of other options with hive just visit :http://karmasphere.com/hive-queries-on-table-data
  • BACKING UP AND RESTORING HBASE DATA• Full shutdown backup using distcp• Using CopyTable to copy data from one table to another• Exporting an HBase table to dump files on HDFS• Restoring HBase data by importing dump files from HDFS• Backing up NameNode metadata• Backing up region starting keys• Cluster replication
  • Gmail dwivedishashwat@gmail.comTwitter shashwat_2010Facebook shriparv@gmail.comSkype shriparv