0% found this document useful (0 votes)
140 views

Hbase Commands: Create ',' '

The document discusses various commands used in HBase shell to perform CRUD (Create, Read, Update, Delete) operations on tables. 1) The hbase shell command is used to connect to the HBase instance and perform table operations. Tables are created with column families using the create command. 2) Data can be inserted into tables using the put command, retrieved using get and scan commands, and updated using put. 3) Tables can be managed using commands like list, describe, disable, enable, alter, exists, drop and truncate. 4) Count command returns number of rows in a table.

Uploaded by

SAMINA ATTARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views

Hbase Commands: Create ',' '

The document discusses various commands used in HBase shell to perform CRUD (Create, Read, Update, Delete) operations on tables. 1) The hbase shell command is used to connect to the HBase instance and perform table operations. Tables are created with column families using the create command. 2) Data can be inserted into tables using the put command, retrieved using get and scan commands, and updated using put. 3) Tables can be managed using commands like list, describe, disable, enable, alter, exists, drop and truncate. 4) Count command returns number of rows in a table.

Uploaded by

SAMINA ATTARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Hbase Commands

● Hbase shell

HBase contains a shell using which you can communicate with HBase. HBase uses the
Hadoop File System to store its data. It will have a master server and region servers.
The data storage will be in the form of regions (tables). These regions will be split up
and stored in region servers.
The master server manages these region servers and all these tasks take place on
HDFS

[cloudera@quickstart ~]$ hbase shell


2020-11-19 21:16:03,253 INFO [main] Configuration.deprecation: hadoop.native.lib is
deprecated. Instead, use io.native.lib.available
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.0-cdh5.12.0, rUnknown, Thu Jun 29 04:42:07 PDT 2017

● Create Table

You can create a table using the create command, here you must specify the table name
and the Column Family name. The syntax to create a table in HBase shell is shown
below.

create ‘<table name>’,’<column family>’

hbase(main):001:0> create 'emp','personal data','professional data'


0 row(s) in 1.4820 seconds
=> Hbase::Table - emp
● Listing a Table

list is the command that is used to list all the tables in HBase. Given below is the syntax
of the list command.
hbase(main):001:0 > list

hbase(main):002:0> list

TABLE
Emp
1 row(s) in 0.0330 seconds
=> ["emp"]

● Disabling a Table

To delete a table or change its settings, you need to first disable the table using the
disable command. ​After disabling the table, you can still sense its existence through list
and exists commands​.Given below is the syntax to disable a table:

disable ‘<table name>’

hbase(main):003:0> disable 'emp'

0 row(s) in 2.3580 seconds

hbase(main):006:0> is_disabled 'emp'

true
0 row(s) in 0.0110 seconds

● Enabling a Table

Syntax to enable a table:

enable ‘<table name>’

hbase(main):007:0> enable 'emp'


0 row(s) in 1.2900 seconds
● Describe Table

This command returns the description of the table. Its syntax is as follows:

hbase> describe 'table name'


Given below is the output of the describe command on the emp table:

hbase(main):008:0> describe 'emp'

Table emp is ENABLED


emp
COLUMN FAMILIES DESCRIPTION
{NAME => 'personal data', DATA_BLOCK_ENCODING => 'NONE',
BLOOMFILTER => 'ROW', R
EPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION =>
'NONE', MIN_VERSIONS =>
'0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE
=> '65536', IN_
MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'professional data', DATA_BLOCK_ENCODING => 'NONE',
BLOOMFILTER => 'ROW
', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION =>
'NONE', MIN_VERSION
S => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE',
BLOCKSIZE => '65536',
IN_MEMORY => 'false', BLOCKCACHE => 'true'}
2 row(s) in 0.0300 seconds

● Alter Command

Alter is the command used to make changes to an existing table. Using this command,
you can change the maximum number of cells of a column family, set and delete table
scope operators, and delete a column family from a table.

★ Changing the Maximum Number of Cells of a Column Family


Given below is the syntax to change the maximum number of cells of a column
family.
hbase> alter 't1', NAME ⇒ 'f1', VERSIONS ⇒ 5

hbase(main):009:0> alter 'emp',NAME => 'personal data', VERSIONS => 5


Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.9680 seconds
● Exist Command

You can verify the existence of a table using the exists command. The following
example shows how to use this command.

hbase(main):010:0> exists 'emp'


Table emp does exist
0 row(s) in 0.0190 seconds

● Drop Table

Using the drop command, you can delete a table. But before dropping a table, you have
to disable it.

hbase(main):011:0> drop 'emp'

ERROR: Table emp is enabled. Disable it first.


Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
hbase(main):012:0> disable 'emp'
drop 0 row(s) in 2.2850 seconds

hbase(main):013:0> drop 'emp'


0 row(s) in 1.2920 second

● Creating Data ( Put command )

Using the put command, you can insert rows into a table. Its syntax is as follows:

put ’<table name>’,’row1’,’<colfamily:colname>’,’<value>’

hbase(main):014:0> create 'emp','personal data','professional data'


0 row(s) in 1.2540 seconds
=> Hbase::Table - emp
hbase(main):015:0> put 'emp','1','personal data:name','Kenil'
0 row(s) in 0.0610 seconds

hbase(main):016:0> put 'emp','1','personal data:city','Mumbai'


0 row(s) in 0.0040 seconds

hbase(main):017:0> put 'emp','1','professional data:designation','MD'


0 row(s) in 0.0110 seconds

hbase(main):018:0> put 'emp','1','professional data:salary','12000000'


0 row(s) in 0.0050 seconds
● Scan Table

The scan command is used to view the data in HTable. Using the scan command, you
can get the table data. Its syntax is as follows:

scan ‘<table name>’

hbase(main):019:0> scan 'emp'


ROW COLUMN+CELL
1 column=personal data:city, timestamp=1605850243459, value=
Mumbai
1 column=personal data:name, timestamp=1605850229636, value=
Kenil
1 column=professional data:designation, timestamp=1605850297
598, value=MD
1 column=professional data:salary, timestamp=1605850355084,
value=12000000
1 row(s) in 0.0240 seconds

● Updating Data ( Put Command )

You can update an existing cell value using the put command.The newly given value
replaces the existing value, updating the row. 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’

hbase(main):020:0> put 'emp','1','personal data:city','Hyderabad'


0 row(s) in 0.0090 seconds

hbase(main):021:0> scan 'emp'


ROW COLUMN+CELL
1 column=personal data:city, timestamp=1605850521832, value=
Hyderabad
1 column=personal data:name, timestamp=1605850229636, value=
Kenil
1 column=professional data:designation, timestamp=1605850297
598, value=MD
1 column=professional data:salary, timestamp=1605850355084,
value=12000000
1 row(s) in 0.0220 seconds
● Read Data ( Get Command )

The get command and the get() method of HTable class are used to read data from a
table in HBase. Using the get command, you can get a single row of data at a time. Its
syntax is as follows:

get ’<table name>’,’row1’

hbase(main):022:0> get 'emp','1',{COLUMN => 'personal data:name'}


COLUMN CELL
personal data:name timestamp=1605850229636, value=Kenil
1 row(s) in 0.0080 seconds

● Delete Data ( Delete Command )

Deleting a Specific Cell in a Table


Using the delete command, you can delete a specific cell in a table. The syntax of delete
command is as follows:
delete ‘<table name>’, ‘<row>’, ‘<column name >’, ‘<time stamp>’

hbase(main):024:0> delete 'emp','1','personal data:name',1605850229636


0 row(s) in 0.0160 seconds

● Count Command

You can count the number of rows of a table using the count command. Its syntax is as
follows:

count ‘<table name>’

hbase(main):027:0> count 'emp'


1 row(s) in 0.0170 seconds
● Truncate Command

This command disables drops and recreates a table. The syntax of truncate is as follows:

hbase> truncate 'table name'

hbase(main):028:0> truncate 'emp'


Truncating 'one' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 1.5950 seconds

You might also like