NOTE! THIS DOCUMENT NO LONGER APPLIES. Newer versions of HBase use a different Shell
See shell for the new shells description.
NOTE! THIS DOCUMENT NO LONGER APPLIES. Newer versions of HBase use a different Shell
See shell for the new shells description.
NOTE! THIS DOCUMENT NO LONGER APPLIES. Newer versions of HBase use a different Shell
See shell for the new shells description.
Hbase Shell Introduction
A Query Language Shell for Hadoop + Hbase
Initial Contributor
Edward Yoon (R&D center, NHN corp.)
How to Start a Shell
Run the following on the command-line:
${HBASE_HOME}/bin/hbase shell [--help]
Usage: ./bin/hbase shell [--master:IP_ADDRESS:PORT] [--html]
You will be presented with the following prompt:
HQL, 0.2.0 version. Copyright (c) 2008 by udanax, licensed to Apache Software Foundation. Type 'help;' for usage. hql >
All commands are terminated with a semi-colon: e.g. Type 'help;' to see list of available commands.
HQL
Table of Contents
1. Query Grammars
1.1 Database administration language
1.2 Data definition language
1.3 Data manipulation language
2. Example Of HQL Uses
2.1 Create the table in a Hbase
2.2 Select data from a table
2.3 Insert data into a table
2.4 Delete data in a table
2.5 How to use external jars in Hbase Shell
Query Grammars
Note that attribute values are quoted with either single or double quotes.
Database administration language
|
Syntax |
Explanation |
|
Help |
Help provides information about the use of shell script. |
|
Show |
Show lists tables. |
|
Describe |
Describe provides information about the columnfamilies in a table. |
|
FS |
Filesystem commands. |
|
JAR |
JAR syntax to run hadoop jar commands. |
|
Clear |
Clear the screen. |
|
Exit |
Exit from the current shell script. |
Data definition language
Data definition langague to define data tables
|
Syntax |
Explanation |
|
Create |
Create a new table. |
|
Alter |
Alter syntax changes the structure of the specified table. |
|
Drop |
Drop columnfamilies in a table or tables. |
|
Truncate |
Truncate cleans all data from a table. |
|
Enable/Disable |
Enable/Disable table lock. |
Data manipulation language
Data manipulation language to manually manipulate data on more detailed parts
|
Syntax |
Explanation |
|
Insert |
Insert one row into the table with a value for specified column in the table. |
|
Delete |
Delete specified rows in table. |
|
Select |
Select syntax retrieves rows from a table. |
Example Of HQL Uses
Create the table in a Hbase
hql > help create;
CREATE Create tables
Syntax:
CREATE TABLE table_name (
column_family_definition [, column_family_definition] ...
)
column_family_definition:
column_family_name
[MAX_VERSIONS=n]
[MAX_LENGTH=n]
[COMPRESSION=NONE|RECORD|BLOCK]
[IN_MEMORY]
[BLOOMFILTER=NONE|BLOOMFILTER|COUNTING_BLOOMFILTER|RETOUCHED_BLOOMFILTER VECTOR_SIZE=n NUM_HASH=n]
CREATE TABLE enables you to create a new table with various options for each column family.
MAX_VERSIONS makes a table keep only the recent n versions in a cell. Its default value is 3, i.e., only the most recent 3 versions of values are stored in a cell.
MAX_LENGTH specifies the maximum size of a column value. By default, the maximum size is unlimited. It is limited only by Integer.MAX_VALUE.
COMPRESSION specifies which compression technique to use for the column family. By default, Hbase does not compress any data.
IN_MEMORY specifies whether to keep the values in the column family in-memory, or not. By default, values are not kept in-memory.
BLOOMFILTER specifies which bloom filter to use for the column family. By default, none of the bloom filters is used. You can specify the options in two ways: with VECTOR_SIZE and NUM_HASH, or with NUM_ENTRIES. VECTOR_SIZE specifies the number of elements in the vector, and NUM_HASH specifies the number of hash functions to use; With NUM_ENTRIES, you specify only the approximated number of entries in the column, and VECTOR_SIZE and NUM_HASH are automatically determined.
hql > CREATE TABLE movieLog_table ( --> year, length, inColor, studioName, vote, producer, actor); hql > CREATE TABLE webtable ( --> contents in_memory max_versions=10 compression=block, --> anchor max_length=256 bloomfilter=counting_bloomfilter --> vector_size=1000000 num_hash=4);
Select data from a table
hql > help select;
SELECT Select values from tables
Syntax:
SELECT { column_name, [, column_name] ... | expr[alias] | *} FROM table_name
[WHERE row='row_key' | STARTING FROM 'row-key' [UNTIL 'stop-key']]
[NUM_VERSIONS = version_count]
[TIMESTAMP 'timestamp']
[LIMIT = row_count]
[INTO FILE 'file_name']
SELECT retrieves a subset of data from the specified table.
STARTING FROM returns all the rows starting from 'row-key'.
NUM_VERSIONS retrieves only the recent n versions of values in a cell.
TIMESTAMP returns only the values with the specified timestamp.
LIMIT limits the number of rows to be returned.
hql > SELECT studioName: FROM movieLog_table WHERE row = 'Star Wars'; +----------------------------+ | title studioName | | ========================== | | Star Wars Fox | +----------------------------+ Successfully print out the selected data.(0.05 sec) hql > SELECT count(studioName:Fox) FROM movieLog_table;
Insert data into a table
hql > help insert;
INSERT Insert values into tables
Syntax:
INSERT INTO table_name
(colmn_name, ...) VALUES ('value', ...)
WHERE row='row_key' [TIMESTAMP 'timestamp'];
column_name:
column_family_name
| column_family_name:column_label_name
INSERT inserts a set of values into a table.
If the specified column already exists, the new value is stored as a new version.
If TIMESTAMP is not specified for the value, the current time is used as its timestamp.
hql > INSERT INTO movieLog_table (year:, length:, inColor:, studioName:, 'vote:user name', producer:, 'actor:hero')
--> VALUES ('1977', '124', 'true', 'Fox', '5', 'George Lucas', 'Mark Hamill')
--> WHERE row='Star Wars';
Delete data in a table
hql > help delete;
DELETE Delete table data
Syntax:
DELETE { column_name, [, column_name] ... | COLUMNFAMILIES(column_family[, column_family] ... | *}
FROM table_name
[WHERE row = 'row-key'];
Asterisk (*) will be delete the all in table.
COLUMNFAMILIES(column_family list) will be delete the all columns in columnfamily.
Specified column_name will be delete the specified column data.
hql > DELETE actor:hero FROM movieLog_table; hql > DELETE actor:hero FROM movieLog_table WHERE row='Star Wars'; hql > DELETE * FROM movieLog_table;
How to use external jars in Hbase Shell
hql > HELP JAR; JAR jarFile [mainClass] args...; ... hql > JAR ./build/hadoop-examples.jar pi 10 10;