Common Commands Example for HBase
status
status
status ‘simple’
status ‘summary’
status ‘detailed’
show_filters
list
describe/exist
describe ‘t1’
exists ‘t1’
list
list ‘abc.*’
create
Create table; pass table name, a dictionary of specifications per column family, and optionally a dictionary of table configuration.
create ‘t1’, {NAME => ‘f1’}, {NAME => ‘f2’}, {NAME => ‘f3’}
create ‘t1’, ‘f1’, ‘f2’, ‘f3’
create 'q3', { NAME => 'count', COMPRESSION => 'LZO', BLOOMFILTER => 'ROW', DATA_BLOCK_ENCODING => 'PREFIX'}
disable/enable/drop
disable ‘t1’
disable_all ‘t.*’
is_disabled ‘t1’
drop ‘t1’
drop_all ‘t.*’
enable ‘t1’
enable_all ‘t.*’
is_enabled ‘t1’
count
count ‘t1’, INTERVAL => 10, CACHE => 1000
- Count interval may be optionally specified
- Current count is shown every 1000 rows by default.
- Default cache size is 10 rows.
put
put ‘t1’, ‘r1’, ‘c1’, ‘value’, ts1
get
get ‘t1’, ‘r1’
get ‘t1’, ‘r1’, {COLUMN => ‘c1’}
get ‘t1’, ‘r1’, {FILTER => “ValueFilter(=, ‘binary:abc’)”}
get ‘t1’, ‘r1’, ‘c1’, ‘c2’
get ‘t1’, ‘r1’, [‘c1’, ‘c2’]
- Besides the default ‘toStringBinary’ format,
get
also supports custom formatting by column.
- Besides the default ‘toStringBinary’ format,
- A user can define a
FORMATTER
by adding it to thecolumn name
in theget
specification. - The
FORMATTER
can be stipulated:- either as a
org.apache.hadoop.hbase.util.Bytes
method name (e.g, toInt, toString) - or as a custom class followed by method name: e.g. ‘c(MyFormatterClass).format’.
- either as a
- Example formatting
cf:qualifier1
andcf:qualifier2
both as Integers:get ‘t1’, ‘r1’ {COLUMN => [‘cf:qualifier1:toInt’, ‘cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt’] }
scan
Scan a table; pass table name and optionally a dictionary of scanner specifications. Scanner specifications may include one or more of:
- TIMERANGE
- FILTER
- LIMIT
- STARTROW
- STOPROW
- TIMESTAMP
- MAXLENGTH
- COLUMNS
- CACHE
- To scan all members of a column family, leave the qualifier empty as in
'col_family:'
scan ‘t1’, {COLUMNS => [‘c1’, ‘c2’], LIMIT => 10, STARTROW => ‘xyz’}
scan ‘t1’, {FILTER => “(PrefixFilter (‘row2’) AND (QualifierFilter (>=, ‘binary:xyz’))) AND (TimestampsFilter ( 123, 456))”}
filter
scan 'airline',{ FILTER => "KeyOnlyFilter()"}
scan 'airline',{ FILTER => "FirstKeyOnlyFilter()"}
scan 'airline', {FILTER => "(PrefixFilter ('row2'))"}
scan 'airline', {FILTER => "(PrefixFilter ('row2')) AND ColumnPrefixFilter('destination')"}
scan 'airline',{FILTER => "MultipleColumnPrefixFilter('source','destination','date')"}
scan 'airline',{FILTER => "ColumnCountGetFilter(2)"}
scan 'airline',{FILTER => "PageFilter(1)"}
scan 'airline',{FILTER => "InclusiveStopFilter('row1')"}
scan 'airline',{ FILTER => "QualifierFilter(=,'binary:flightno')"}
scan 'airline', { COLUMNS => 'flightbetween:source', LIMIT => 4, FILTER => "ValueFilter( =, 'binaryprefix:hyd' )" }
scan 'airline' ,{ FILTER => "SingleColumnValueFilter('flightbetween','source',=, 'binary:hyd')" }