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 => ...
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  ...
DELETEPut a delete cell value at specified table/row/column  and optionally timestamp coordinates.Eg:Delete ‘table’,’colfa...
DELETEALLDelete all cells in a given row; pass a table name, row, and optionally a column and timestampDelete ‘table’,’row...
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, {CO...
PUTPut a cell value at specified table/row/column and optionally  timestamp coordinates.To put a cell value into table t1 ...
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 s...
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 ...
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 fami...
SCRIPT FOR HBASEcat hbase_user_part_scan.txt scan user,  {STARTROW => user_1, STOPROW => user_3}  exit$ hbase shell hbase_...
USING BASH SCRIPT#!/bin/bash TABLE=$1 STARTROW=$2  STOPROW=$3 exec hbase shell <<EOF scan  "${TABLE}", {STARTROW => "${STA...
SEE WHEN A RECORD WAS ADDEDget user, user_1‘Time.at(1344763701019/1000)Will show you the human understable time likeSun Au...
SCHEMA DESIGNWe can take advantage of table schema and store all information realated to a given user in one row (but in t...
ADDING MORE DATA TO HBASE TABLES$ hbase shellhbase(main):001:0> create user, info, friendhbase(main):002:0> put user, user...
SPECIFYING DIFFERENT CONFIGURATION FOR HBASE SHELLHBase Shell is started by using the hbase shell  command. This command u...
SOME HELPFUL COMMANDS : EXERCISEGet a specified row by using the get command:Delete a specified cell by using the delete c...
ANSWERSget t1, row1delete t1, row1, f1:c1‘deleteall t1, row1‘balance_switch true
CHECKING THE CONSISTENCY OF AN HBASE CLUSTERBin/hbase hbck
YOU WANT TO QUERY HBASE USING SQL????Use hive to query . For that you need to create a table in hive as   external table t...
BACKING UP AND RESTORING HBASE DATA• Full shutdown backup using distcp• Using CopyTable to copy data from one table to  an...
Gmail      dwivedishashwat@gmail.comTwitter    shashwat_2010Facebook   shriparv@gmail.comSkype      shriparv
Upcoming SlideShare
Loading in …5
×

Hbase interact with shell

2,705 views
2,593 views

Published on

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,705
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
51
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Hbase interact with shell

  1. 1. dwivedishashwat@gmail.com
  2. 2. LISTList all tables in HBaseSyntax :Htase :> list
  3. 3. CREATECreate table;Pass table nameSyntax :Hbase :> creat ‘tablename’,’colFamily’
  4. 4. 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
  5. 5. DESCRIBEDescribe the named table:e.g.hbase> describe table1
  6. 6. 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
  7. 7. DELETEPut a delete cell value at specified table/row/column and optionally timestamp coordinates.Eg:Delete ‘table’,’colfam:columnname’
  8. 8. DELETEALLDelete all cells in a given row; pass a table name, row, and optionally a column and timestampDelete ‘table’,’rowkey’
  9. 9. DISABLEDisable the named table:e.g."hbase> disable t1"
  10. 10. DROPDrop the named table. Table must first be disabled.Eg:Drop ‘tablename’
  11. 11. ENABLEEnable the named tableEg:Enable ‘tablename’
  12. 12. EXISTSDoes the named table exist?e.g."hbase> exists t1"
  13. 13. 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}
  14. 14. 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
  15. 15. SCANScan a tableTo scan all members of a column family, leave the qualifier empty as in col_family:.hbase> scan t1’
  16. 16. STATUSShow cluster status.Can be summary, simple, or detailed.The default is summary.Examples:hbase> statushbase> status simplehbase> status summaryhbase> status detailed
  17. 17. SHUTDOWNShut down the cluster.
  18. 18. TRUNCATEDisables, drops and recreates the specified table.
  19. 19. VERSIONOutput this HBase version
  20. 20. 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}
  21. 21. EXITTypehbase> exitto leave the HBase Shell
  22. 22. SCRIPTINGYou can pass scripts to the HBase Shell by doing the following:bin/hbase shell PATH_TO_SCRIPT
  23. 23. 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
  24. 24. 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.
  25. 25. 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
  26. 26. 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
  27. 27. 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
  28. 28. 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
  29. 29. 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
  30. 30. 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
  31. 31. ANSWERSget t1, row1delete t1, row1, f1:c1‘deleteall t1, row1‘balance_switch true
  32. 32. CHECKING THE CONSISTENCY OF AN HBASE CLUSTERBin/hbase hbck
  33. 33. 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
  34. 34. 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
  35. 35. Gmail dwivedishashwat@gmail.comTwitter shashwat_2010Facebook shriparv@gmail.comSkype shriparv

×