Basic Hbase commands
Hbase commands:
HBase has a shell through which we can communicate with Hbase. The operations which can be performed on Hbase are given below.
DDL Operations:
1) Create:
A table is created by giving table name and column family names.. The syntax is as below:
Text Box: create ‘<table name>’,’<column family>’
2) List:
Text Box: list
This command returns the list of all tables which are available.
3) Disable:
To delete a table or change any table settings, we need to disable the table first.
Text Box: disable ‘<table name>’
Below command disables the table.
Verification:
After disabling the table, we can verify it through the ‘scan’ command which will throw an error.
Text Box: hbase(main):001:0> scan ‘<table name>’
ERROR: ‘<table name>’ does not exist
4) disable_all:
Multiple tables can be disabled at a time using disable_all command.
Text Box: disable_all ‘emp.*’
For example: TTo disable all the tables which starts with word ‘emp’, we can use as below:
5) Is_disabled:
Below command is to check whether a table is in disabled state or not by using ‘is_disabled’ command.
Syntax is as below:
Text Box: is_disabled ‘<table name>’
6) Enable:
Text Box: enable ‘<table name>’
we can enable a disabled table using the above command.
7) is_enabled:
We can verify if the table is in enabled stated or not using the below command
Text Box: is_enabled ‘<table name>’
8) Describe:
Text Box: describe ‘<table name>’
This command shows the description of the table. Below is the syntax.
9) Alter:
To modify the existing table alter command is used. Using Alter command, we can perform below operations:
§ Add new column family
§ Delete existing column family.
§ Table can be set to Read only mode.
§ maximum no.of cells for a column family can be set.
§ compression technique to be enabled for the table.
Text Box: alter ‘<table name>’, NAME => ‘< column family name >’
a) Syntax to add new column family to an existing table is shown:
b) Syntax to delete existing column family from the table is shown:
Text Box: alter ‘<table name>’, delete => ‘< column family name >’
c) Syntax to set table to read-only mode:
Text Box: alter ‘<table name>’, READONLY
d) Syntax to set maximum versions to a column family is shown below:
Text Box: alter ‘<table name>’, NAME => ‘< column family name >’ , VERSIONS => 5
e) Syntax to enable compression to the table:
Text Box: alter ‘<table name>’, NAME => ‘< column family name >’ , COMPRESSION => ‘snappy’
10) Exists:
Text Box: exists ‘<table name>’
To verify whether a table is exists or not using the below command.
11) Drop:
A table is dropped by using the below command. However, to drop any table, first we need to disable that table and then drop it.
12) Drop_all:
Multiple tables can be droped by using ‘drop_all’ command. Below is the syntax:
Ex: To drop all the tables which starts with word ‘emp’, then use as below.
Text Box: disable_all ‘emp.*’
First we need to disable these tables.
Text Box: drop_all ‘emp.*’
DML Operations:
Below are the DML operations that can be performed in Hbase.
1) Put:
Text Box: put ‘<table name>’ , ‘<row>’, ‘<column family:column name>’, ‘<value>’
Put command is used to insert data in the table. Below is the syntax for the same:
Ex:
Text Box: put ‘student’, ‘1’, ‘dept:name’, ‘chemistry’
2) Update:
Text Box: put ‘<table name>’ , ‘<rowid>’, ‘<column family:column name>’, ‘<new value>’
Using update command, we could update existing cell value to a new value. Below is the syntax:
Ex:
If below command is executed, depart name of the student will get changed to physics from chemistry
Text Box: put ‘student’, ‘1’, ‘dept:name’, ‘Physics’
3) Get:
Text Box: get ‘<table name>’ , ‘<rowid>’
Using the Get command, we can read the data from Hbase.
Below is the syntax.
Reading a specific column:
below is the syntax to read a specific cell from the column family, .
Text Box: get ‘<table name>’ , ‘<rowid>’, {COLUMN => ‘<column family:column name>’}
4) Delete:
Text Box: delete ‘<table name>’ , ‘<rowid>’, ‘<column name>’, ‘<timestamp>’
Using delete command, we can delete specific cell from the table. Below is the syntax:
5) Delete all:
Text Box: delete_all ‘<table name>’ , ‘<rowid>’
Using Delete all command, all the cells in a particular row can be deleted.
6) Scan:
Text Box: scan ‘<table name>’
Using Scan command, we can view data in the table.
7) Count:
Text Box: count ‘<table name>’
Using count command, we can count no.of rows in a table.
8) Truncate:
Using truncate command, we could truncate the table. It disables, drops and re-creates an empty table.
Text Box: truncate ‘<table name>’
Hbase commands:
HBase has a shell through which we can communicate with Hbase. The operations which can be performed on Hbase are given below.
DDL Operations:
1) Create:
A table is created by giving table name and column family names.. The syntax is as below:
Text Box: create ‘<table name>’,’<column family>’
2) List:
Text Box: list
This command returns the list of all tables which are available.
3) Disable:
To delete a table or change any table settings, we need to disable the table first.
Text Box: disable ‘<table name>’
Below command disables the table.
Verification:
After disabling the table, we can verify it through the ‘scan’ command which will throw an error.
Text Box: hbase(main):001:0> scan ‘<table name>’
ERROR: ‘<table name>’ does not exist
4) disable_all:
Multiple tables can be disabled at a time using disable_all command.
Text Box: disable_all ‘emp.*’
For example: TTo disable all the tables which starts with word ‘emp’, we can use as below:
5) Is_disabled:
Below command is to check whether a table is in disabled state or not by using ‘is_disabled’ command.
Syntax is as below:
Text Box: is_disabled ‘<table name>’
6) Enable:
Text Box: enable ‘<table name>’
we can enable a disabled table using the above command.
7) is_enabled:
We can verify if the table is in enabled stated or not using the below command
Text Box: is_enabled ‘<table name>’
8) Describe:
Text Box: describe ‘<table name>’
This command shows the description of the table. Below is the syntax.
9) Alter:
To modify the existing table alter command is used. Using Alter command, we can perform below operations:
§ Add new column family
§ Delete existing column family.
§ Table can be set to Read only mode.
§ maximum no.of cells for a column family can be set.
§ compression technique to be enabled for the table.
Text Box: alter ‘<table name>’, NAME => ‘< column family name >’
a) Syntax to add new column family to an existing table is shown:
b) Syntax to delete existing column family from the table is shown:
Text Box: alter ‘<table name>’, delete => ‘< column family name >’
c) Syntax to set table to read-only mode:
Text Box: alter ‘<table name>’, READONLY
d) Syntax to set maximum versions to a column family is shown below:
Text Box: alter ‘<table name>’, NAME => ‘< column family name >’ , VERSIONS => 5
e) Syntax to enable compression to the table:
Text Box: alter ‘<table name>’, NAME => ‘< column family name >’ , COMPRESSION => ‘snappy’
10) Exists:
Text Box: exists ‘<table name>’
To verify whether a table is exists or not using the below command.
11) Drop:
A table is dropped by using the below command. However, to drop any table, first we need to disable that table and then drop it.
12) Drop_all:
Multiple tables can be droped by using ‘drop_all’ command. Below is the syntax:
Ex: To drop all the tables which starts with word ‘emp’, then use as below.
Text Box: disable_all ‘emp.*’
First we need to disable these tables.
Text Box: drop_all ‘emp.*’
DML Operations:
Below are the DML operations that can be performed in Hbase.
1) Put:
Text Box: put ‘<table name>’ , ‘<row>’, ‘<column family:column name>’, ‘<value>’
Put command is used to insert data in the table. Below is the syntax for the same:
Ex:
Text Box: put ‘student’, ‘1’, ‘dept:name’, ‘chemistry’
2) Update:
Text Box: put ‘<table name>’ , ‘<rowid>’, ‘<column family:column name>’, ‘<new value>’
Using update command, we could update existing cell value to a new value. Below is the syntax:
Ex:
If below command is executed, depart name of the student will get changed to physics from chemistry
Text Box: put ‘student’, ‘1’, ‘dept:name’, ‘Physics’
3) Get:
Text Box: get ‘<table name>’ , ‘<rowid>’
Using the Get command, we can read the data from Hbase.
Below is the syntax.
Reading a specific column:
below is the syntax to read a specific cell from the column family, .
Text Box: get ‘<table name>’ , ‘<rowid>’, {COLUMN => ‘<column family:column name>’}
4) Delete:
Text Box: delete ‘<table name>’ , ‘<rowid>’, ‘<column name>’, ‘<timestamp>’
Using delete command, we can delete specific cell from the table. Below is the syntax:
5) Delete all:
Text Box: delete_all ‘<table name>’ , ‘<rowid>’
Using Delete all command, all the cells in a particular row can be deleted.
6) Scan:
Text Box: scan ‘<table name>’
Using Scan command, we can view data in the table.
7) Count:
Text Box: count ‘<table name>’
Using count command, we can count no.of rows in a table.
8) Truncate:
Using truncate command, we could truncate the table. It disables, drops and re-creates an empty table.
Text Box: truncate ‘<table name>’
0 Comments