SlideShare uma empresa Scribd logo
1 de 35
dwivedishashwat@gmail.com
LIST

List all tables in HBase

Syntax :

Htase :> list
CREATE
Create table;


Pass table name


Syntax :
Hbase :> creat ‘tablename’,’colFamily’
MORE EXAPLES
hbase> 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', 'f3'


hbase> create 'tableToBeCreated', {NAME => 'colFammily1', VERSIONS =>
  1, TTL => 2592000, BLOCKCACHE => true
DESCRIBE

Describe the named table:

e.g.

hbase> describe 'table1'
COUNT

Count 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
DELETE

Put a delete cell value at specified table/row/column
  and optionally timestamp coordinates.

Eg:

Delete ‘table’,’colfam:columnname’
DELETEALL

Delete all cells in a given row; pass a table name, row,
 and optionally a column and timestamp

Delete ‘table’,’rowkey’
DISABLE

Disable the named table:
e.g.

"hbase> disable 't1'"
DROP

Drop the named table. Table must first be disabled.

Eg:

Drop ‘tablename’
ENABLE

Enable the named table

Eg:

Enable ‘tablename’
EXISTS

Does the named table exist?
e.g.

"hbase> exists 't1'"
GET

Get row or cell contents; pass table name, row,

hbase> get 't1', 'r1'
hbase> 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}
PUT

Put 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 'c1'


do:


hbase> put 't1', 'r1', 'c1', 'value'
SCAN

Scan a tableTo scan all members of a column family, leave the
  qualifier empty as in 'col_family:'.


hbase> scan 't1’
STATUS

Show cluster status.
Can be 'summary', 'simple', or 'detailed'.
The default is 'summary'.

Examples:
hbase> status
hbase> status 'simple'
hbase> status 'summary'
hbase> status 'detailed'
SHUTDOWN

Shut down the cluster.
TRUNCATE

Disables, drops and recreates the
 specified table.
VERSION

Output this HBase version
ALTER
Alter 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'}
EXIT

Type
hbase> exit

to leave the HBase Shell
SCRIPTING

You can pass scripts to the HBase Shell by doing the
  following:

bin/hbase shell PATH_TO_SCRIPT
SOME HBASE TRICKS

echo "create 'user', 'info'" | hbase shell

Using 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" 
End
This will create 4 users with user#1 to 4 and put email
  address too
SCRIPT FOR HBASE

cat hbase_user_part_scan.txt scan 'user',
  {STARTROW => 'user_1', STOPROW => 'user_3'}
  exit

$ hbase shell hbase_user_part_scan.txt

This 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 ADDED

get 'user', 'user_1‘

Time.at(1344763701019/1000)

Will show you the human understable time like

Sun Aug 12 11:28:21 +0200 2012
SCHEMA DESIGN

We 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 shell
hbase(main):001:0> create 'user', 'info', 'friend'
hbase(main):002:0> put 'user', 'username1', 'friend:username2',
   'childhood'
hbase(main):003:0> put 'user', 'username1', 'friend:username3',
   'childhood'
hbase(main):004:0> put 'user', 'username2', 'friend:username3',
   'childhood'
hbase(main):005:0> put 'user', 'username2', 'friend:username4',
   'childhood'
hbase(main):006:0> put 'user', 'username3', 'friend:username5',
   'childhood'
hbase(main):007:0> put 'user', 'username1', 'friend:username5',
   'childhood‘
Or you can write an script to create these value
SPECIFYING DIFFERENT CONFIGURATION FOR HBASE SHELL

HBase 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 different
configuration for HBase Shell to use:

hbase --config <configuration_directory> shell
SOME HELPFUL COMMANDS : EXERCISE

Get 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
ANSWERS

get 't1', 'row1'
delete 't1', 'row1', 'f1:c1‘
deleteall 't1', 'row1‘
balance_switch true
CHECKING THE CONSISTENCY OF AN HBASE CLUSTER

Bin/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 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.com

Twitter    shashwat_2010

Facebook   shriparv@gmail.com

Skype      shriparv

Mais conteúdo relacionado

Mais procurados (18)

My sql.ppt
My sql.pptMy sql.ppt
My sql.ppt
 
SQL WORKSHOP::Lecture 11
SQL WORKSHOP::Lecture 11SQL WORKSHOP::Lecture 11
SQL WORKSHOP::Lecture 11
 
Learn plsql
Learn plsqlLearn plsql
Learn plsql
 
Les10
Les10Les10
Les10
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
Frameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPFrameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHP
 
Raj mysql
Raj mysqlRaj mysql
Raj mysql
 
data constraints,group by
data constraints,group by data constraints,group by
data constraints,group by
 
Les02
Les02Les02
Les02
 
Mysql quick guide
Mysql quick guideMysql quick guide
Mysql quick guide
 
Introducción rápida a SQL
Introducción rápida a SQLIntroducción rápida a SQL
Introducción rápida a SQL
 
Blocks In Drupal
Blocks In DrupalBlocks In Drupal
Blocks In Drupal
 
Mysql Ppt
Mysql PptMysql Ppt
Mysql Ppt
 
MYSQL
MYSQLMYSQL
MYSQL
 
Try PostgreSQL on linux
Try PostgreSQL on linuxTry PostgreSQL on linux
Try PostgreSQL on linux
 
Les12
Les12Les12
Les12
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 

Destaque (6)

Inventory system
Inventory systemInventory system
Inventory system
 
Configure h base hadoop and hbase client
Configure h base hadoop and hbase clientConfigure h base hadoop and hbase client
Configure h base hadoop and hbase client
 
Edge
EdgeEdge
Edge
 
H base development
H base developmentH base development
H base development
 
H base
H baseH base
H base
 
Introduction to apache hadoop
Introduction to apache hadoopIntroduction to apache hadoop
Introduction to apache hadoop
 

Semelhante a Hbase interact with shell

Semelhante a Hbase interact with shell (20)

Rhbase
RhbaseRhbase
Rhbase
 
Hbase
HbaseHbase
Hbase
 
Hive commands
Hive commandsHive commands
Hive commands
 
MYSQL
MYSQLMYSQL
MYSQL
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Hive integration
Hive integrationHive integration
Hive integration
 
Apache HBase - Lab Assignment
Apache HBase - Lab AssignmentApache HBase - Lab Assignment
Apache HBase - Lab Assignment
 
Sql cheat sheet
Sql cheat sheetSql cheat sheet
Sql cheat sheet
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
SQL : Structured Query Language
SQL : Structured Query LanguageSQL : Structured Query Language
SQL : Structured Query Language
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
Commands
CommandsCommands
Commands
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 

Mais de Shashwat Shriparv (20)

Learning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptxLearning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptx
 
LibreOffice 7.3.pptx
LibreOffice 7.3.pptxLibreOffice 7.3.pptx
LibreOffice 7.3.pptx
 
Kerberos Architecture.pptx
Kerberos Architecture.pptxKerberos Architecture.pptx
Kerberos Architecture.pptx
 
Suspending a Process in Linux.pptx
Suspending a Process in Linux.pptxSuspending a Process in Linux.pptx
Suspending a Process in Linux.pptx
 
Kerberos Architecture.pptx
Kerberos Architecture.pptxKerberos Architecture.pptx
Kerberos Architecture.pptx
 
Command Seperators.pptx
Command Seperators.pptxCommand Seperators.pptx
Command Seperators.pptx
 
Upgrading hadoop
Upgrading hadoopUpgrading hadoop
Upgrading hadoop
 
Hadoop migration and upgradation
Hadoop migration and upgradationHadoop migration and upgradation
Hadoop migration and upgradation
 
R language introduction
R language introductionR language introduction
R language introduction
 
Hive query optimization infinity
Hive query optimization infinityHive query optimization infinity
Hive query optimization infinity
 
H base introduction & development
H base introduction & developmentH base introduction & development
H base introduction & development
 
Hbase
HbaseHbase
Hbase
 
My sql
My sqlMy sql
My sql
 
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
 
Linux 4 you
Linux 4 youLinux 4 you
Linux 4 you
 
Next generation technology
Next generation technologyNext generation technology
Next generation technology
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
 
I pv6
I pv6I pv6
I pv6
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 

Hbase interact with shell

  • 2. LIST List all tables in HBase Syntax : Htase :> list
  • 3. CREATE Create table; Pass table name Syntax : Hbase :> creat ‘tablename’,’colFamily’
  • 4. MORE EXAPLES hbase> 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', 'f3' hbase> create 'tableToBeCreated', {NAME => 'colFammily1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true
  • 5. DESCRIBE Describe the named table: e.g. hbase> describe 'table1'
  • 6. COUNT Count 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. DELETE Put a delete cell value at specified table/row/column and optionally timestamp coordinates. Eg: Delete ‘table’,’colfam:columnname’
  • 8. DELETEALL Delete all cells in a given row; pass a table name, row, and optionally a column and timestamp Delete ‘table’,’rowkey’
  • 9. DISABLE Disable the named table: e.g. "hbase> disable 't1'"
  • 10. DROP Drop the named table. Table must first be disabled. Eg: Drop ‘tablename’
  • 11. ENABLE Enable the named table Eg: Enable ‘tablename’
  • 12. EXISTS Does the named table exist? e.g. "hbase> exists 't1'"
  • 13. GET Get row or cell contents; pass table name, row, hbase> get 't1', 'r1' hbase> 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. PUT Put 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 'c1' do: hbase> put 't1', 'r1', 'c1', 'value'
  • 15. SCAN Scan a tableTo scan all members of a column family, leave the qualifier empty as in 'col_family:'. hbase> scan 't1’
  • 16. STATUS Show cluster status. Can be 'summary', 'simple', or 'detailed'. The default is 'summary'. Examples: hbase> status hbase> status 'simple' hbase> status 'summary' hbase> status 'detailed'
  • 18. TRUNCATE Disables, drops and recreates the specified table.
  • 20. ALTER Alter 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'}
  • 22. SCRIPTING You can pass scripts to the HBase Shell by doing the following: bin/hbase shell PATH_TO_SCRIPT
  • 23. SOME HBASE TRICKS echo "create 'user', 'info'" | hbase shell Using 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" End This will create 4 users with user#1 to 4 and put email address too
  • 24. SCRIPT FOR HBASE cat hbase_user_part_scan.txt scan 'user', {STARTROW => 'user_1', STOPROW => 'user_3'} exit $ hbase shell hbase_user_part_scan.txt This script will scan the user table and give output.
  • 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. SEE WHEN A RECORD WAS ADDED get 'user', 'user_1‘ Time.at(1344763701019/1000) Will show you the human understable time like Sun Aug 12 11:28:21 +0200 2012
  • 27. SCHEMA DESIGN We 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. ADDING MORE DATA TO HBASE TABLES $ hbase shell hbase(main):001:0> create 'user', 'info', 'friend' hbase(main):002:0> put 'user', 'username1', 'friend:username2', 'childhood' hbase(main):003:0> put 'user', 'username1', 'friend:username3', 'childhood' hbase(main):004:0> put 'user', 'username2', 'friend:username3', 'childhood' hbase(main):005:0> put 'user', 'username2', 'friend:username4', 'childhood' hbase(main):006:0> put 'user', 'username3', 'friend:username5', 'childhood' hbase(main):007:0> put 'user', 'username1', 'friend:username5', 'childhood‘ Or you can write an script to create these value
  • 29. SPECIFYING DIFFERENT CONFIGURATION FOR HBASE SHELL HBase 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 different configuration for HBase Shell to use: hbase --config <configuration_directory> shell
  • 30. SOME HELPFUL COMMANDS : EXERCISE Get 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. ANSWERS get 't1', 'row1' delete 't1', 'row1', 'f1:c1‘ deleteall 't1', 'row1‘ balance_switch true
  • 32. CHECKING THE CONSISTENCY OF AN HBASE CLUSTER Bin/hbase hbck
  • 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. 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. Gmail dwivedishashwat@gmail.com Twitter shashwat_2010 Facebook shriparv@gmail.com Skype shriparv