http://www.linuxidc.com/Linux/2015-03/114670.htm
http://www.cnblogs.com/end/archive/2011/04/12/2013804.html
http://www.cnblogs.com/end/archive/2011/04/12/2013804.html
Disabled by default. Example:
hbase> scan 't1', {RAW => true, VERSIONS => 10}
Besides the default 'toStringBinary' format, 'scan' supports custom formatting
by column. A user can define a FORMATTER by adding it to the column name in
the scan specification. The FORMATTER can be stipulated:
1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString)
2. or as a custom class followed by method name: e.g. 'c(MyFormatterClass).format'.
Example formatting cf:qualifier1 and cf:qualifier2 both as Integers:
hbase> scan 't1', {COLUMNS => ['cf:qualifier1:toInt',
'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] }
Note that you can specify a FORMATTER by column only (cf:qualifer). You cannot
specify a FORMATTER for all columns of a column family.
Scan can also be used directly from a table, by first getting a reference to a
table, like such:
hbase> t = get_table 't'
hbase> t.scan
Note in the above situation, you can still provide all the filtering, columns,
options, etc as described above.
hbase(main):018:0> scan 'scores'
ROW COLUMN+CELL
Jerry column=course:art, timestamp=1467043674178, value=80
Jerry column=course:math, timestamp=1467043661806, value=100
Jerry column=grade:, timestamp=1467043649929, value=2
Tom column=course:art, timestamp=1467043633328, value=97
Tom column=course:math, timestamp=1467043619083, value=87
Tom column=grade:, timestamp=1467043589481, value=1
2 row(s) in 0.0640 seconds
hbase(main):019:0> get 'scores', 'Tom'
COLUMN CELL
course:art timestamp=1467043633328, value=97
course:math timestamp=1467043619083, value=87
grade: timestamp=1467043589481, value=1
3 row(s) in 0.0310 seconds
hbase(main):020:0> create 'scores', 'grade', 'course'
ERROR: Table already exists: scores!
Here is some help for this command:
Creates a table. Pass a table name, and a set of column family
specifications (at least one), and, optionally, table configuration.
Column specification can be a simple string (name), or a dictionary
(dictionaries are described below in main help output), necessarily
including NAME attribute.
Examples:
Create a table with namespace=ns1 and table qualifier=t1
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
Create a table with namespace=default and table qualifier=t1
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
hbase> # The above in shorthand would be the following:
hbase> create 't1', 'f1', 'f2', 'f3'
hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}
Table configuration options can be put at the end.
Examples:
hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']
hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40']
hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' }
hbase> # Optionally pre-split the table into NUMREGIONS, using
hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => 1}
You can also keep around a reference to the created table:
hbase> t1 = create 't1', 'f1'
Which gives you a reference to the table named 't1', on which you can then
call methods.
hbase(main):021:0> version
0.98.20-hadoop2, r9624f3a9eb76f84656a41de0e2099c97f949e831, Tue Jun 7 17:40:20 PDT 2016
hbase(main):022:0> describe 'member'
Table member is ENABLED
member
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION =>
'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCA
CHE => 'true'}
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'N
ONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE
=> 'true'}
{NAME => 'member_id', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION
=> 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCK
CACHE => 'true'}
3 row(s) in 0.0970 seconds
hbase(main):023:0> alter 'member',{NAME=>'member_id',METHOD=>'delete'}
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.6480 seconds
hbase(main):024:0> describe 'member'
Table member is ENABLED
member
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION =>
'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCA
CHE => 'true'}
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'N
ONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE
=> 'true'}
2 row(s) in 0.3380 seconds
hbase(main):025:0> is_enabled 'member'
true
0 row(s) in 0.0510 seconds
hbase(main):026:0> is_disabled 'member'
false
0 row(s) in 0.0480 seconds
hbase(main):027:0> list
TABLE
member
scores
2 row(s) in 0.0220 seconds
=> ["member", "scores"]
hbase(main):028:0> exists 'member'
Table member does exist
0 row(s) in 0.0490 seconds
hbase(main):029:0> exists 'member_temp'
Table member_temp does not exist
0 row(s) in 0.0470 seconds
hbase(main):030:0> scan 'member'
ROW COLUMN+CELL
0 row(s) in 0.0330 seconds
hbase(main):031:0> put'member','scutshuxue','info:age','24'
0 row(s) in 0.0270 seconds
hbase(main):032:0>
hbase(main):033:0* put'member','scutshuxue','info:birthday','1987-06-17'
0 row(s) in 0.0050 seconds
hbase(main):034:0>
hbase(main):035:0* put'member','scutshuxue','info:company','alibaba'
0 row(s) in 0.0100 seconds
hbase(main):036:0>
hbase(main):037:0* put'member','scutshuxue','address:contry','china'
0 row(s) in 0.0240 seconds
hbase(main):038:0>
hbase(main):039:0* put'member','scutshuxue','address:province','zhejiang'
0 row(s) in 0.0050 seconds
hbase(main):040:0>
hbase(main):041:0* put'member','scutshuxue','address:city','hangzhou'
0 row(s) in 0.0130 seconds
hbase(main):042:0> scan 'member'
ROW COLUMN+CELL
scutshuxue column=address:city, timestamp=1467044198878, value=hangzhou
scutshuxue column=address:contry, timestamp=1467044197312, value=china
scutshuxue column=address:province, timestamp=1467044197387, value=zhejiang
scutshuxue column=info:age, timestamp=1467044197146, value=24
scutshuxue column=info:birthday, timestamp=1467044197222, value=1987-06-17
scutshuxue column=info:company, timestamp=1467044197268, value=alibaba
1 row(s) in 0.0320 seconds
hbase(main):043:0> put'member','xiaofeng','info:birthday','1987-4-17'
0 row(s) in 0.0160 seconds
hbase(main):044:0>
hbase(main):045:0* put'member','xiaofeng','info:favorite','movie'
0 row(s) in 0.0090 seconds
hbase(main):046:0>
hbase(main):047:0* put'member','xiaofeng','info:company','alibaba'
0 row(s) in 0.0030 seconds
hbase(main):048:0>
hbase(main):049:0* put'member','xiaofeng','address:contry','china'
0 row(s) in 0.0070 seconds
hbase(main):050:0>
hbase(main):051:0* put'member','xiaofeng','address:province','guangdong'
0 row(s) in 0.0040 seconds
hbase(main):052:0>
hbase(main):053:0* put'member','xiaofeng','address:city','jieyang'
0 row(s) in 0.0080 seconds
hbase(main):054:0>
hbase(main):055:0* put'member','xiaofeng','address:town','xianqiao'
0 row(s) in 0.0110 seconds
hbase(main):056:0> scan 'member'
ROW COLUMN+CELL
scutshuxue column=address:city, timestamp=1467044198878, value=hangzhou
scutshuxue column=address:contry, timestamp=1467044197312, value=china
scutshuxue column=address:province, timestamp=1467044197387, value=zhejiang
scutshuxue column=info:age, timestamp=1467044197146, value=24
scutshuxue column=info:birthday, timestamp=1467044197222, value=1987-06-17
scutshuxue column=info:company, timestamp=1467044197268, value=alibaba
xiaofeng column=address:city, timestamp=1467044214211, value=jieyang
xiaofeng column=address:contry, timestamp=1467044214109, value=china
xiaofeng column=address:province, timestamp=1467044214168, value=guangdong
xiaofeng column=address:town, timestamp=1467044215505, value=xianqiao
xiaofeng column=info:birthday, timestamp=1467044213955, value=1987-4-17
xiaofeng column=info:company, timestamp=1467044214068, value=alibaba
xiaofeng column=info:favorite, timestamp=1467044214015, value=movie
2 row(s) in 0.0300 seconds
hbase(main):057:0> get member scutshuxue
NameError: undefined local variable or method `scutshuxue' for #<Object:0x1945458>
hbase(main):058:0> get member scutshuxue'
hbase(main):059:0' get 'member' 'scutshuxue'
hbase(main):060:0'
hbase(main):061:0'
hbase(main):062:0' [root@cdh1 conf]# hbase shell
2016-06-27 09:18:14,682 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 0.98.20-hadoop2, r9624f3a9eb76f84656a41de0e2099c97f949e831, Tue Jun 7 17:40:20 PDT 2016
hbase(main):001:0> get 'member' 'scutshuxue'
ERROR: wrong number of arguments (1 for 2)
Here is some help for this command:
Get row or cell contents; pass table name, row, and optionally
a dictionary of column(s), timestamp, timerange and versions. Examples:
hbase> get 'ns1:t1', 'r1'
hbase> get 't1', 'r1'
hbase> get 't1', 'r1', {TIMERANGE => [ts1, ts2]}
hbase> get 't1', 'r1', {COLUMN => 'c1'}
hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> get 't1', 'r1', 'c1'
hbase> get 't1', 'r1', 'c1', 'c2'
hbase> get 't1', 'r1', ['c1', 'c2']
hbsase> get 't1','r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}}
hbsase> get 't1','r1', {COLUMN => 'c1', AUTHORIZATIONS => ['PRIVATE','SECRET']}
Besides the default 'toStringBinary' format, 'get' also supports custom formatting by
column. A user can define a FORMATTER by adding it to the column name in the get
specification. The FORMATTER can be stipulated:
1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString)
2. or as a custom class followed by method name: e.g. 'c(MyFormatterClass).format'.
Example formatting cf:qualifier1 and cf:qualifier2 both as Integers:
hbase> get 't1', 'r1' {COLUMN => ['cf:qualifier1:toInt',
'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] }
Note that you can specify a FORMATTER by column only (cf:qualifer). You cannot specify
a FORMATTER for all columns of a column family.
The same commands also can be run on a reference to a table (obtained via get_table or
create_table). Suppose you had a reference t to table 't1', the corresponding commands
would be:
hbase> t.get 'r1'
hbase> t.get 'r1', {TIMERANGE => [ts1, ts2]}
hbase> t.get 'r1', {COLUMN => 'c1'}
hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> t.get 'r1', 'c1'
hbase> t.get 'r1', 'c1', 'c2'
hbase> t.get 'r1', ['c1', 'c2']
hbase(main):002:0> get 'member' ,'scutshuxue'
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/user/local/hbase-0.98.20-hadoop2/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/user/local/hadoop-2.6.0/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
COLUMN CELL
address:city timestamp=1467044198878, value=hangzhou
address:contry timestamp=1467044197312, value=china
address:province timestamp=1467044197387, value=zhejiang
info:age timestamp=1467044197146, value=24
info:birthday timestamp=1467044197222, value=1987-06-17
info:company timestamp=1467044197268, value=alibaba
6 row(s) in 0.4280 seconds
hbase(main):003:0> scan 'member'
ROW COLUMN+CELL
scutshuxue column=address:city, timestamp=1467044198878, value=hangzhou
scutshuxue column=address:contry, timestamp=1467044197312, value=china
scutshuxue column=address:province, timestamp=1467044197387, value=zhejiang
scutshuxue column=info:age, timestamp=1467044197146, value=24
scutshuxue column=info:birthday, timestamp=1467044197222, value=1987-06-17
scutshuxue column=info:company, timestamp=1467044197268, value=alibaba
xiaofeng column=address:city, timestamp=1467044214211, value=jieyang
xiaofeng column=address:contry, timestamp=1467044214109, value=china
xiaofeng column=address:province, timestamp=1467044214168, value=guangdong
xiaofeng column=address:town, timestamp=1467044215505, value=xianqiao
xiaofeng column=info:birthday, timestamp=1467044213955, value=1987-4-17
xiaofeng column=info:company, timestamp=1467044214068, value=alibaba
xiaofeng column=info:favorite, timestamp=1467044214015, value=movie
2 row(s) in 0.1100 seconds
hbase(main):004:0> get 'member' ,'scutshuxue','info'
COLUMN CELL
info:age timestamp=1467044197146, value=24
info:birthday timestamp=1467044197222, value=1987-06-17
info:company timestamp=1467044197268, value=alibaba
3 row(s) in 0.0530 seconds
hbase(main):005:0> get 'member' ,'scutshuxue'
COLUMN CELL
address:city timestamp=1467044198878, value=hangzhou
address:contry timestamp=1467044197312, value=china
address:province timestamp=1467044197387, value=zhejiang
info:age timestamp=1467044197146, value=24
info:birthday timestamp=1467044197222, value=1987-06-17
info:company timestamp=1467044197268, value=alibaba
6 row(s) in 0.0190 seconds
hbase(main):006:0> get 'member' ,'scutshuxue','info:age'
COLUMN CELL
info:age timestamp=1467044197146, value=24
1 row(s) in 0.0530 seconds
hbase(main):007:0> get 'member' ,'scutshuxue','info:company'
COLUMN CELL
info:company timestamp=1467044197268, value=alibaba
1 row(s) in 0.0140 seconds
hbase(main):008:0> get 'member' ,'scutshuxue','info:age'
COLUMN CELL
info:age timestamp=1467044197146, value=24
1 row(s) in 0.0180 seconds
hbase(main):009:0> put 'member','scutshuxue','info:age' ,'99'
0 row(s) in 0.1070 seconds
hbase(main):010:0> get 'member' ,'scutshuxue','info:age'
COLUMN CELL
info:age timestamp=1467044462445, value=99
1 row(s) in 0.0190 seconds
hbase(main):011:0> get 'member' ,'scutshuxue','info'
COLUMN CELL
info:age timestamp=1467044462445, value=99
info:birthday timestamp=1467044197222, value=1987-06-17
info:company timestamp=1467044197268, value=alibaba
3 row(s) in 0.0280 seconds
hbase(main):012:0> get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1321586238965}
COLUMN CELL
0 row(s) in 0.0230 seconds
hbase(main):013:0> get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1467044462445}
COLUMN CELL
info:age timestamp=1467044462445, value=99
1 row(s) in 0.0070 seconds
hbase(main):014:0> get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1467044462445}
COLUMN CELL
info:age timestamp=1467044462445, value=99
1 row(s) in 0.0210 seconds
hbase(main):015:0> get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1467044197146}
COLUMN CELL
info:age timestamp=1467044197146, value=24
1 row(s) in 0.0230 seconds
hbase(main):016:0> scan 'member'
ROW COLUMN+CELL
scutshuxue column=address:city, timestamp=1467044198878, value=hangzhou
scutshuxue column=address:contry, timestamp=1467044197312, value=china
scutshuxue column=address:province, timestamp=1467044197387, value=zhejiang
scutshuxue column=info:age, timestamp=1467044462445, value=99
scutshuxue column=info:birthday, timestamp=1467044197222, value=1987-06-17
scutshuxue column=info:company, timestamp=1467044197268, value=alibaba
xiaofeng column=address:city, timestamp=1467044214211, value=jieyang
xiaofeng column=address:contry, timestamp=1467044214109, value=china
xiaofeng column=address:province, timestamp=1467044214168, value=guangdong
xiaofeng column=address:town, timestamp=1467044215505, value=xianqiao
xiaofeng column=info:birthday, timestamp=1467044213955, value=1987-4-17
xiaofeng column=info:company, timestamp=1467044214068, value=alibaba
xiaofeng column=info:favorite, timestamp=1467044214015, value=movie
2 row(s) in 0.0800 seconds
hbase(main):017:0> get 'member','temp'
COLUMN CELL
0 row(s) in 0.0240 seconds
hbase(main):018:0> get 'member','scutshuxue','info:age'
COLUMN CELL
info:age timestamp=1467044462445, value=99
1 row(s) in 0.0110 seconds
hbase(main):019:0> get 'member','xiaofeng','info:age'
COLUMN CELL
0 row(s) in 0.0240 seconds
hbase(main):020:0> put 'member','xiaofeng','info:age','110'
0 row(s) in 0.0130 seconds
hbase(main):021:0> get 'member','xiaofeng','info:age'
COLUMN CELL
info:age timestamp=1467044830542, value=110
1 row(s) in 0.0210 seconds
hbase(main):022:0> delete 'member','xiaofeng','info:age'
0 row(s) in 0.0700 seconds
hbase(main):023:0> get 'member','xiaofeng','info:age'
COLUMN CELL
0 row(s) in 0.0420 seconds
hbase(main):024:0> get 'member','xiaofeng','info'
COLUMN CELL
info:birthday timestamp=1467044213955, value=1987-4-17
info:company timestamp=1467044214068, value=alibaba
info:favorite timestamp=1467044214015, value=movie
3 row(s) in 0.0130 seconds
hbase(main):025:0> put 'member','xiaofeng','info:age','110'
0 row(s) in 0.0130 seconds
hbase(main):026:0> get 'member','xiaofeng','info'
COLUMN CELL
info:age timestamp=1467044893778, value=110
info:birthday timestamp=1467044213955, value=1987-4-17
info:company timestamp=1467044214068, value=alibaba
info:favorite timestamp=1467044214015, value=movie
4 row(s) in 0.0270 seconds
hbase(main):027:0> get 'member','xiaofeng'
COLUMN CELL
address:city timestamp=1467044214211, value=jieyang
address:contry timestamp=1467044214109, value=china
address:province timestamp=1467044214168, value=guangdong
address:town timestamp=1467044215505, value=xianqiao
info:age timestamp=1467044893778, value=110
info:birthday timestamp=1467044213955, value=1987-4-17
info:company timestamp=1467044214068, value=alibaba
info:favorite timestamp=1467044214015, value=movie
8 row(s) in 0.0280 seconds
hbase(main):028:0> deleteall 'member','xiaofeng'
0 row(s) in 0.0180 seconds
hbase(main):029:0> get 'member','xiaofeng'
COLUMN CELL
0 row(s) in 0.0040 seconds
hbase(main):030:0> count 'member'
1 row(s) in 0.1440 seconds
=> 1
hbase(main):031:0> incr 'member','xiaofeng','info:age'
COUNTER VALUE = 1
0 row(s) in 0.0340 seconds
hbase(main):032:0> get 'member','xiaofeng'
COLUMN CELL
info:age timestamp=1467044961664, value=\x00\x00\x00\x00\x00\x00\x00\x01
1 row(s) in 0.0230 seconds
hbase(main):033:0> incr 'member','xiaofeng','info:age'
COUNTER VALUE = 2
0 row(s) in 0.0250 seconds
hbase(main):034:0> get 'member','xiaofeng'
COLUMN CELL
info:age timestamp=1467045000778, value=\x00\x00\x00\x00\x00\x00\x00\x02
1 row(s) in 0.0090 seconds
hbase(main):035:0> get_counter 'member','xiaofeng','info:age'
COUNTER VALUE = 2
hbase(main):036:0> truncate 'member'
Truncating 'member' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 1.8810 seconds
hbase(main):037:0>
hbase 基本命令
最新推荐文章于 2024-04-12 15:55:30 发布