hbase shell operate

1, start hdfs 

[hadoop@alamps sbin]$ ./start-all.sh
This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh
Starting namenodes on [alamps]
alamps: starting namenode, logging to /home/hadoop/app/hadoop-2.4.1/logs/hadoop-hadoop-namenode-alamps.out
alamps: starting datanode, logging to /home/hadoop/app/hadoop-2.4.1/logs/hadoop-hadoop-datanode-alamps.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /home/hadoop/app/hadoop-2.4.1/logs/hadoop-hadoop-secondarynamenode-alamps.out
starting yarn daemons
starting resourcemanager, logging to /home/hadoop/app/hadoop-2.4.1/logs/yarn-hadoop-resourcemanager-alamps.out
alamps: starting nodemanager, logging to /home/hadoop/app/hadoop-2.4.1/logs/yarn-hadoop-nodemanager-alamps.out
[hadoop@alamps sbin]$ jps
6976 Jps
6352 DataNode
6775 NodeManager
6233 NameNode
6508 SecondaryNameNode
6654 ResourceManager

2,  start hbase 
[hadoop@alamps bin]$ ./start-hbase.sh 
alamps: starting zookeeper, logging to /home/hadoop/hbase-0.96.2/bin/../logs/hbase-hadoop-zookeeper-alamps.out
starting master, logging to /home/hadoop/hbase-0.96.2/bin/../logs/hbase-hadoop-master-alamps.out
localhost: starting regionserver, logging to /home/hadoop/hbase-0.96.2/bin/../logs/hbase-hadoop-regionserver-alamps.out
[hadoop@alamps bin]$ jps
6352 DataNode
7283 HQuorumPeer
6775 NodeManager
6233 NameNode
7529 Jps
7338 HMaster
6508 SecondaryNameNode
6654 ResourceManager
7455 HRegionServer
[hadoop@alamps bin]$ 

3, hbase shell 
=========================
进入hbase命令行
./hbase shell

显示hbase中的表
list

hbase(main):001:0> list
TABLE                                                                                                                                                                                                    
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/hbase-0.96.2/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.4.1/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.
0 row(s) in 1.8360 seconds

=> []
hbase(main):002:0> create 'user', 'info1', 'data1'
0 row(s) in 0.6790 seconds

=> Hbase::Table - user
hbase(main):003:0> list
TABLE                                                                                                                                                                                                    
user                                                                                                                                                                                                     
1 row(s) in 0.0670 seconds

=> ["user"]
hbase(main):004:0> create 'user', {NAME => 'info', VERSIONS => '3'}

ERROR: Table already exists: user!

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

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):005:0> create 'user', {NAME => 'info1', VERSIONS => '3'}

ERROR: Table already exists: user!

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

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):006:0> san 'user'
NoMethodError: undefined method `san' for #<Object:0x689973>

hbase(main):007:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          
0 row(s) in 0.0330 seconds

hbase(main):008:0> create 'user', {NAME => 'info1', VERSIONS => '3'}

ERROR: Table already exists: user!

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

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):009:0> put 'user', 'rk0001', 'info:name', 'zhangsan'

ERROR: Failed 1 action: org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: Column family info does not exist in region user,,1511513666149.7dafe6d1353a5be73a69aa03ffdbe8d3. in table 'user', {NAME => 'data1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => '2147483647', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}, {NAME => 'info1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => '2147483647', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
    at org.apache.hadoop.hbase.regionserver.HRegionServer.doBatchOp(HRegionServer.java:4100)
    at org.apache.hadoop.hbase.regionserver.HRegionServer.doNonAtomicRegionMutation(HRegionServer.java:3380)
    at org.apache.hadoop.hbase.regionserver.HRegionServer.multi(HRegionServer.java:3284)
    at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:26935)
    at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2185)
    at org.apache.hadoop.hbase.ipc.RpcServer$Handler.run(RpcServer.java:1889)
: 1 time, 

Here is some help for this command:
Put a cell 'value' at specified table/row/column and optionally
timestamp coordinates.  To put a cell value into table 'ns1:t1' or 't1'
at row 'r1' under column 'c1' marked with the time 'ts1', do:

  hbase> put 'ns1:t1', 'r1', 'c1', 'value', ts1

The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:

  hbase> t.put 'r1', 'c1', 'value', ts1


hbase(main):010:0> put 'user', 'rk0001', 'info1:name', 'zhangsan'
0 row(s) in 0.0050 seconds

hbase(main):011:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
1 row(s) in 0.0330 seconds

hbase(main):012:0> delete 'user'

ERROR: wrong number of arguments (1 for 3)

Here is some help for this command:
Put a delete cell value at specified table/row/column and optionally
timestamp coordinates.  Deletes must match the deleted cell's
coordinates exactly.  When scanning, a delete cell suppresses older
versions. To delete a cell from  't1' at row 'r1' under column 'c1'
marked with the time 'ts1', do:

  hbase> delete 'ns1:t1', 'r1', 'c1', ts1
  hbase> delete 't1', 'r1', 'c1', ts1

The same command can also be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:

  hbase> t.delete 'r1', 'c1',  ts1


hbase(main):013:0> list
TABLE                                                                                                                                                                                                    
user                                                                                                                                                                                                     
1 row(s) in 0.0580 seconds

=> ["user"]
hbase(main):014:0> delete 'user'

ERROR: wrong number of arguments (1 for 3)

Here is some help for this command:
Put a delete cell value at specified table/row/column and optionally
timestamp coordinates.  Deletes must match the deleted cell's
coordinates exactly.  When scanning, a delete cell suppresses older
versions. To delete a cell from  't1' at row 'r1' under column 'c1'
marked with the time 'ts1', do:

  hbase> delete 'ns1:t1', 'r1', 'c1', ts1
  hbase> delete 't1', 'r1', 'c1', ts1

The same command can also be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:

  hbase> t.delete 'r1', 'c1',  ts1


hbase(main):015:0> delete user
NameError: undefined local variable or method `user' for #<Object:0x689973>

hbase(main):016:0> disable 'user'
0 row(s) in 2.7590 seconds

hbase(main):017:0> delete 'user'

ERROR: wrong number of arguments (1 for 3)

Here is some help for this command:
Put a delete cell value at specified table/row/column and optionally
timestamp coordinates.  Deletes must match the deleted cell's
coordinates exactly.  When scanning, a delete cell suppresses older
versions. To delete a cell from  't1' at row 'r1' under column 'c1'
marked with the time 'ts1', do:

  hbase> delete 'ns1:t1', 'r1', 'c1', ts1
  hbase> delete 't1', 'r1', 'c1', ts1

The same command can also be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:

  hbase> t.delete 'r1', 'c1',  ts1


hbase(main):018:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          

ERROR: user is disabled.

Here is some help for this command:
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,
or COLUMNS, CACHE

If no columns are specified, all columns will be scanned.
To scan all members of a column family, leave the qualifier empty as in
'col_family:'.

The filter can be specified in two ways:
1. Using a filterString - more information on this is available in the
Filter Language document attached to the HBASE-4176 JIRA
2. Using the entire package name of the filter.

Some examples:

  hbase> scan 'hbase:meta'
  hbase> scan 'hbase:meta', {COLUMNS => 'info:regioninfo'}
  hbase> scan 'ns1:t1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]}
  hbase> scan 't1', {FILTER => "(PrefixFilter ('row2') AND
    (QualifierFilter (>=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))"}
  hbase> scan 't1', {FILTER =>
    org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}

For experts, there is an additional option -- CACHE_BLOCKS -- which
switches block caching for the scanner on (true) or off (false).  By
default it is enabled.  Examples:

  hbase> scan 't1', {COLUMNS => ['c1', 'c2'], CACHE_BLOCKS => false}

Also for experts, there is an advanced option -- RAW -- which instructs the
scanner to return all cells (including delete markers and uncollected deleted
cells). This option cannot be combined with requesting specific COLUMNS.
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):019:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          

ERROR: user is disabled.

Here is some help for this command:
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,
or COLUMNS, CACHE

If no columns are specified, all columns will be scanned.
To scan all members of a column family, leave the qualifier empty as in
'col_family:'.

The filter can be specified in two ways:
1. Using a filterString - more information on this is available in the
Filter Language document attached to the HBASE-4176 JIRA
2. Using the entire package name of the filter.

Some examples:

  hbase> scan 'hbase:meta'
  hbase> scan 'hbase:meta', {COLUMNS => 'info:regioninfo'}
  hbase> scan 'ns1:t1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]}
  hbase> scan 't1', {FILTER => "(PrefixFilter ('row2') AND
    (QualifierFilter (>=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))"}
  hbase> scan 't1', {FILTER =>
    org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}

For experts, there is an additional option -- CACHE_BLOCKS -- which
switches block caching for the scanner on (true) or off (false).  By
default it is enabled.  Examples:

  hbase> scan 't1', {COLUMNS => ['c1', 'c2'], CACHE_BLOCKS => false}

Also for experts, there is an advanced option -- RAW -- which instructs the
scanner to return all cells (including delete markers and uncollected deleted
cells). This option cannot be combined with requesting specific COLUMNS.
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):020:0> enable 'user'
0 row(s) in 0.6160 seconds

hbase(main):021:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
1 row(s) in 0.0670 seconds

hbase(main):022:0> put 'user', 'rk0001', 'info1:gender', 'female'
0 row(s) in 0.0130 seconds

hbase(main):023:0> scan 'user'
ROW                            COLUMN+CELL                                                                             
 rk0001                        column=info1:gender, timestamp=1511514513331, value=female                              
 rk0001                        column=info1:name, timestamp=1511514175935, value=zhangsan                              
1 row(s) in 0.0360 seconds



hbase(main):025:0> put 'user', 'rk0001', 'info1:age', 20
0 row(s) in 0.0250 seconds

hbase(main):026:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
1 row(s) in 0.0290 seconds


Here is some help for this command:
Put a cell 'value' at specified table/row/column and optionally
timestamp coordinates.  To put a cell value into table 'ns1:t1' or 't1'
at row 'r1' under column 'c1' marked with the time 'ts1', do:

  hbase> put 'ns1:t1', 'r1', 'c1', 'value', ts1

The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:

  hbase> t.put 'r1', 'c1', 'value', ts1


hbase(main):028:0> put 'user', 'rk0001', 'data1:pic', 'picture'
0 row(s) in 0.0080 seconds

hbase(main):029:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=data1:pic, timestamp=1511514630008, value=picture                                                                                             
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
1 row(s) in 0.0270 seconds

hbase(main):030:0> get 'user' rk001
SyntaxError: (hbase):30: syntax error, unexpected tIDENTIFIER

get 'user' rk001
               ^

hbase(main):031:0> get 'user', 'rk0001'
COLUMN                                              CELL                                                                                                                                                 
 data1:pic                                          timestamp=1511514630008, value=picture                                                                                                               
 info1:age                                          timestamp=1511514577793, value=20                                                                                                                    
 info1:gender                                       timestamp=1511514513331, value=female                                                                                                                
 info1:name                                         timestamp=1511514175935, value=zhangsan                                                                                                              
4 row(s) in 0.0650 seconds

hbase(main):032:0> get 'user', 'rk0001', 'info1'
COLUMN                                              CELL                                                                                                                                                 
 info1:age                                          timestamp=1511514577793, value=20                                                                                                                    
 info1:gender                                       timestamp=1511514513331, value=female                                                                                                                
 info1:name                                         timestamp=1511514175935, value=zhangsan                                                                                                              
3 row(s) in 0.0390 seconds




hbase(main):034:0> get 'user', 'rk0001', 'info1:name', 'info1:age'
COLUMN                                              CELL                                                                                                                                                 
 info1:age                                          timestamp=1511514577793, value=20                                                                                                                    
 info1:name                                         timestamp=1511514175935, value=zhangsan                                                                                                              
2 row(s) in 0.0260 seconds

hbase(main):035:0> get 'user', 'rk0001', 'info1', 'data1'
COLUMN                                              CELL                                                                                                                                                 
 data1:pic                                          timestamp=1511514630008, value=picture                                                                                                               
 info1:age                                          timestamp=1511514577793, value=20                                                                                                                    
 info1:gender                                       timestamp=1511514513331, value=female                                                                                                                
 info1:name                                         timestamp=1511514175935, value=zhangsan                                                                                                              
4 row(s) in 0.0220 seconds

hbase(main):036:0> get 'user', 'rk0001', {COLUMN => ['info1', 'data1']}
COLUMN                                              CELL                                                                                                                                                 
 data1:pic                                          timestamp=1511514630008, value=picture                                                                                                               
 info1:age                                          timestamp=1511514577793, value=20                                                                                                                    
 info1:gender                                       timestamp=1511514513331, value=female                                                                                                                
 info1:name                                         timestamp=1511514175935, value=zhangsan                                                                                                              
4 row(s) in 0.0200 seconds

hbase(main):037:0> get 'user', 'rk0001', {COLUMN => ['info1:name', 'data1:pic']}
COLUMN                                              CELL                                                                                                                                                 
 data1:pic                                          timestamp=1511514630008, value=picture                                                                                                               
 info1:name                                         timestamp=1511514175935, value=zhangsan                                                                                                              
2 row(s) in 0.0400 seconds

hbase(main):038:0> get 'user', 'rk0001', {COLUMN => 'info1:name', VERSIONS => 5}
COLUMN                                              CELL                                                                                                                                                 
 info1:name                                         timestamp=1511514175935, value=zhangsan                                                                                                              
1 row(s) in 0.0130 seconds

hbase(main):039:0> get 'user', 'rk0001', {FILTER => "ValueFilter(=, 'binary:图片')"}
COLUMN                                              CELL                                                                                                                                                 
0 row(s) in 0.0750 seconds

hbase(main):040:0> get 'user', 'rk0001', {FILTER => "(QualifierFilter(=,'substring:a'))"}
COLUMN                                              CELL                                                                                                                                                 
 info1:age                                          timestamp=1511514577793, value=20                                                                                                                    
 info1:name                                         timestamp=1511514175935, value=zhangsan                                                                                                              
2 row(s) in 0.0290 seconds

hbase(main):041:0> put 'user', 'rk0002', 'info1:name', 'fanbingbing'
0 row(s) in 0.0110 seconds

hbase(main):042:0> put 'user', 'rk0002', 'info1:gender', 'female'
0 row(s) in 0.0040 seconds

hbase(main):043:0> put 'user', 'rk0002', 'info1:nationality', '中国'
0 row(s) in 0.0130 seconds

hbase(main):044:0> get surscan 'user'
NoMethodError: undefined method `surscan' for #<Object:0x689973>

hbase(main):045:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=data1:pic, timestamp=1511514630008, value=picture                                                                                             
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:gender, timestamp=1511515593309, value=female                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0280 seconds

hbase(main):046:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=data1:pic, timestamp=1511514630008, value=picture                                                                                             
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:gender, timestamp=1511515593309, value=female                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0330 seconds

hbase(main):047:0> get 'user', 'rk0002', {FILTER => "ValueFilter(=, 'binary:中国')"}
COLUMN                                              CELL                                                                                                                                                 
 info1:nationality                                  timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                                              
1 row(s) in 0.0130 seconds

hbase(main):048:0> scan 'user', {COLUMNS => 'info'}
ROW                                                 COLUMN+CELL                                                                                                                                          

ERROR: Unknown column family! Valid column names: data1:*, info1:*

Here is some help for this command:
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,
or COLUMNS, CACHE

If no columns are specified, all columns will be scanned.
To scan all members of a column family, leave the qualifier empty as in
'col_family:'.

The filter can be specified in two ways:
1. Using a filterString - more information on this is available in the
Filter Language document attached to the HBASE-4176 JIRA
2. Using the entire package name of the filter.

Some examples:

  hbase> scan 'hbase:meta'
  hbase> scan 'hbase:meta', {COLUMNS => 'info:regioninfo'}
  hbase> scan 'ns1:t1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]}
  hbase> scan 't1', {FILTER => "(PrefixFilter ('row2') AND
    (QualifierFilter (>=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))"}
  hbase> scan 't1', {FILTER =>
    org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}




hbase(main):049:0> scan 'user', {COLUMNS => 'info1'}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:gender, timestamp=1511515593309, value=female                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0570 seconds

hbase(main):050:0> scan 'user', {COLUMNS => 'info1', RAW => true, VERSIONS => 5}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:gender, timestamp=1511515593309, value=female                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0280 seconds

hbase(main):051:0> scan 'user', {COLUMNS => 'info1', RAW => true, VERSIONS => 3}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:gender, timestamp=1511515593309, value=female                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0360 seconds

hbase(main):052:0> scan 'user', {COLUMNS => ['info1', 'data1']}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=data1:pic, timestamp=1511514630008, value=picture                                                                                             
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:gender, timestamp=1511515593309, value=female                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0270 seconds

hbase(main):053:0> scan 'user', {COLUMNS => ['info1:name', 'data1:pic']}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=data1:pic, timestamp=1511514630008, value=picture                                                                                             
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
2 row(s) in 0.0380 seconds

hbase(main):054:0> scan 'user', {COLUMNS => 'info1:name'}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
2 row(s) in 0.0200 seconds

hbase(main):055:0> scan 'user', {COLUMNS => 'info1:name', VERSIONS => 5}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
2 row(s) in 0.0250 seconds

hbase(main):056:0> scan 'user', {COLUMNS => 'info1:name', VERSIONS => 1}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
2 row(s) in 0.0230 seconds

hbase(main):057:0> scan 'user', {COLUMNS => 'info1:name', VERSIONS => 1}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
2 row(s) in 0.0230 seconds

hbase(main):058:0> scan 'people', {COLUMNS => ['info1', 'data1'], FILTER => "(QualifierFilter(=,'substring:a'))"}

ERROR: Unknown table people!

Here is some help for this command:
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,
or COLUMNS, CACHE

If no columns are specified, all columns will be scanned.
To scan all members of a column family, leave the qualifier empty as in
'col_family:'.

The filter can be specified in two ways:
1. Using a filterString - more information on this is available in the
Filter Language document attached to the HBASE-4176 JIRA
2. Using the entire package name of the filter.

Some examples:

  hbase> scan 'hbase:meta'
  hbase> scan 'hbase:meta', {COLUMNS => 'info:regioninfo'}
  hbase> scan 'ns1:t1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]}
  hbase> scan 't1', {FILTER => "(PrefixFilter ('row2') AND
    (QualifierFilter (>=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))"}
  hbase> scan 't1', {FILTER =>
    org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}

For experts, there is an additional option -- CACHE_BLOCKS -- which
switches block caching for the scanner on (true) or off (false).  By
default it is enabled.  Examples:

  hbase> scan 't1', {COLUMNS => ['c1', 'c2'], CACHE_BLOCKS => false}

Also for experts, there is an advanced option -- RAW -- which instructs the
scanner to return all cells (including delete markers and uncollected deleted
cells). This option cannot be combined with requesting specific COLUMNS.
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):059:0> scan 'user', {COLUMNS => ['info1', 'data1'], FILTER => "(QualifierFilter(=,'substring:a'))"}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0220 seconds

hbase(main):060:0> scan 'user', {COLUMNS => 'info1', STARTROW => 'rk0001', ENDROW => 'rk0003'}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:gender, timestamp=1511515593309, value=female                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0250 seconds

hbase(main):061:0> scan 'user',{FILTER=>"PrefixFilter('rk')"}
ROW                                                 COLUMN+CELL                                                                                                                                          
 rk0001                                             column=data1:pic, timestamp=1511514630008, value=picture                                                                                             
 rk0001                                             column=info1:age, timestamp=1511514577793, value=20                                                                                                  
 rk0001                                             column=info1:gender, timestamp=1511514513331, value=female                                                                                           
 rk0001                                             column=info1:name, timestamp=1511514175935, value=zhangsan                                                                                           
 rk0002                                             column=info1:gender, timestamp=1511515593309, value=female                                                                                           
 rk0002                                             column=info1:name, timestamp=1511515593274, value=fanbingbing                                                                                        
 rk0002                                             column=info1:nationality, timestamp=1511515595502, value=\xE4\xB8\xAD\xE5\x9B\xBD                                                                    
2 row(s) in 0.0430 seconds

hbase(main):062:0> [hadoop@alamps sbin]$ scan 'user', {TIMERANGE => [1511514175935, 1511514630008]}
-bash: scan: command not found
[hadoop@alamps sbin]$ scan 'user', {TIMERANGE => [1511514175935]}
-bash: scan: command not found
[hadoop@alamps sbin]$ delete 'user', 'rk0001', 'info:name'
-bash: delete: command not found
[hadoop@alamps sbin]$ delete 'user', 'rk0001', 'info1:name'
-bash: delete: command not found
[hadoop@alamps sbin]$ delete 'user', 'rk0001', 'info1:name'
-bash: delete: command not found
[hadoop@alamps sbin]$ truncate 'user'
truncate: you must specify one of `--size' or `--reference'
Try `truncate --help' for more information.
[hadoop@alamps sbin]$ truncate 'user'
truncate: you must specify one of `--size' or `--reference'
Try `truncate --help' for more information.
[hadoop@alamps sbin]$ alter 'user', NAME => 'f2'
-bash: alter: command not found
[hadoop@alamps sbin]$ alter 'user', NAME => 'f1', METHOD => 'delete' 
-bash: alter: command not found
[hadoop@alamps sbin]$ drop 'user'
-bash: drop: command not found
[hadoop@alamps sbin]$ get 'user', 'rk0002', {COLUMN => ['info1:name', 'data1:pic']}
-bash: get: command not found
[hadoop@alamps sbin]$ get 'user', 'rk0001', {COLUMN => ['info1:name', 'data1:pic']}
-bash: get: command not found
[hadoop@alamps sbin]$ get 'user'
-bash: get: command not found
[hadoop@alamps sbin]$ hbase shell
2017-11-24 01:48:53,388 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.96.2-hadoop2, r1581096, Mon Mar 24 16:03:18 PDT 2014

hbase(main):001:0> get 'user', 'rk0002', {COLUMN => ['info1:name', 'data1:pic']}
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/hbase-0.96.2/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.4.1/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                                                                                                                                                 
 info1:name                                         timestamp=1511515593274, value=fanbingbing                                                                                                           
1 row(s) in 0.0750 seconds

hbase(main):002:0> list
TABLE                                                                                                                                                                                                    
user                                                                                                                                                                                                     
1 row(s) in 0.1340 seconds

=> ["user"]
hbase(main):003:0> get 'user'

 

posted @ 2017-11-24 18:00  Alamps  阅读(831)  评论(0编辑  收藏  举报