Hbase shell <一>

来源:互联网 发布:webgl编程指南 pdf 编辑:程序博客网 时间:2024/06/06 04:03

创建表

Here is some help for this command:Creates a table. Pass a table name, and a set of column familyspecifications (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', REGION_REPLICATION => 2, 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 thencall methods.

PUT操作

hbase(main):001:0> putERROR: wrong number of arguments (0 for 4)Here is some help for this command:Put a cell 'value' at specified table/row/column and optionallytimestamp 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'  hbase> put 't1', 'r1', 'c1', 'value'  hbase> put 't1', 'r1', 'c1', 'value', ts1  hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}  hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}  hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}The same commands also can be run on a table reference. Suppose you had a referencet to table 't1', the corresponding command would be:  hbase> t.put 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}

GET操作

hbase(main):002:0> getERROR: wrong number of arguments (0 for 2)Here is some help for this command:Get row or cell contents; pass table name, row, and optionallya 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']  hbase> get 't1', 'r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}}  hbase> get 't1', 'r1', {COLUMN => 'c1', AUTHORIZATIONS => ['PRIVATE','SECRET']}  hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE'}  hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}Besides the default 'toStringBinary' format, 'get' also supports custom formatting bycolumn.  A user can define a FORMATTER by adding it to the column name in the getspecification.  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:qualifier).  You cannot specifya 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 orcreate_table). Suppose you had a reference t to table 't1', the corresponding commandswould 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> t.get 'r1', {CONSISTENCY => 'TIMELINE'}  hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}

SCAN操作
hbase(main):003:0> scanERROR: wrong number of arguments (0 for 1)Here is some help for this command:Scan a table; pass table name and optionally a dictionary of scannerspecifications.  Scanner specifications may include one or more of:TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, ROWPREFIXFILTER, TIMESTAMP,MAXLENGTH or COLUMNS, CACHE or RAW, VERSIONSIf 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 theFilter Language document attached to the HBASE-4176 JIRA2. 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', {REVERSED => true}  hbase> scan 't1', {ROWPREFIXFILTER => 'row2', FILTER => "    (QualifierFilter (>=, 'binary:xyz')) AND (TimestampsFilter ( 123, 456))"}  hbase> scan 't1', {FILTER =>    org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}  hbase> scan 't1', {CONSISTENCY => 'TIMELINE'}For setting the Operation Attributes   hbase> scan 't1', { COLUMNS => ['c1', 'c2'], ATTRIBUTES => {'mykey' => 'myvalue'}}  hbase> scan 't1', { COLUMNS => ['c1', 'c2'], AUTHORIZATIONS => ['PRIVATE','SECRET']}For experts, there is an additional option -- CACHE_BLOCKS -- whichswitches block caching for the scanner on (true) or off (false).  Bydefault it is enabled.  Examples:  hbase> scan 't1', {COLUMNS => ['c1', 'c2'], CACHE_BLOCKS => false}Also for experts, there is an advanced option -- RAW -- which instructs thescanner to return all cells (including delete markers and uncollected deletedcells). 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 formattingby column.  A user can define a FORMATTER by adding it to the column name inthe 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:qualifier).  You cannotspecify a FORMATTER for all columns of a column family.Scan can also be used directly from a table, by first getting a reference to atable, like such:  hbase> t = get_table 't'  hbase> t.scanNote in the above situation, you can still provide all the filtering, columns,options, etc as described above.
DELETE操作
hbase(main):005:0* deleteERROR: wrong number of arguments (0 for 3)Here is some help for this command:Put a delete cell value at specified table/row/column and optionallytimestamp coordinates.  Deletes must match the deleted cell'scoordinates exactly.  When scanning, a delete cell suppresses olderversions. 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  hbase> delete 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}The same command can also be run on a table reference. Suppose you had a referencet to table 't1', the corresponding command would be:  hbase> t.delete 'r1', 'c1',  ts1  hbase> t.delete 'r1', 'c1',  ts1, {VISIBILITY=>'PRIVATE|SECRET'}



0 0