Hbase/HbaseShell

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

Initial Contributor

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.

HELP [function_name];

Show

Show lists tables.

SHOW tables;

Describe

Describe provides information about the columnfamilies in a table.

DESC table_name;

FS

Filesystem commands.

FS [-option] arguments...;

JAR

JAR syntax to run hadoop jar commands.

JAR jarFile [mainClass] args...;

Clear

Clear the screen.

CLEAR;

Exit

Exit from the current shell script.

EXIT;

Data definition language

Data definition langague to define data tables

Syntax

Explanation

Create

Create a new table.

CREATE TABLE table_name (
 column_family_definition
 [, column_family_spec]
 ...
)

colum_family_definition:
column_family_name
 [MAX_VERSIONS=n]
 [MAX_LENGTH=n]
 [COMPRESSION=NONE|BLOCK|RECORD]
 [IN_MEMORY]
 [BLOOMFILTER=NONE|BLOOMFILTER|COUNTING_BLOOMFILTER|RETOUCHED_BLOOMFILTER VECTOR_SIZE=n NUM_HASH=n]

Alter

Alter syntax changes the structure of the specified table.

ALTER TABLE table_name
 alter_definition [, alter_definition] ...

alter_definition:
 ADD column_family_definition
 | ADD (column_family_definition, ...)
 | DROP column_family_name
 | CHANGE column_family_name column_family_definition

Drop

Drop columnfamilies in a table or tables.

DROP [ALL|TABLE table_name1[, table_name2, ...]];

Truncate

Truncate cleans all data from a table.

TRUNCATE TABLE table_name;

Enable/Disable

Enable/Disable table lock.

[ENABLE|DISABLE] [ALL|table_name];

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.

INSERT INTO table_name (colmn_name, ...)
 VALUES ('value', ...)
 WHERE row = 'row-key'
 [TIMESTAMP 'timestamp'];

Delete

Delete specified rows in table.

DELETE { column_name, [, column_name] ... | COLUMNFAMILIES(column_family[, column_family] ... | *}
 FROM table_name
 [WHERE row = 'row-key'];

Select

Select syntax retrieves rows from a table.
Several aggregate operators: COUNT()

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']

column_name:
 column_family_name
 | column_family_name:column_label_name

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.

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.

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.

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'];
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;

last edited 2008-11-25 00:58:54 by stack