Hbase-03-shell get 命令

2021/7/20 7:06:02

本文主要是介绍Hbase-03-shell get 命令,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

获取一行或者一个单元数据

hbase:001:0> help 'get'
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']
  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 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:qualifier). You can set a
formatter for all columns (including, all key parts) using the "FORMATTER"
and "FORMATTER_CLASS" options. The default "FORMATTER_CLASS" is
"org.apache.hadoop.hbase.util.Bytes".

  hbase> get 't1', 'r1', {FORMATTER => 'toString'}
  hbase> get 't1', 'r1', {FORMATTER_CLASS => 'org.apache.hadoop.hbase.util.Bytes', FORMATTER => 'toString'}

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> t.get 'r1', {CONSISTENCY => 'TIMELINE'}
  hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}

表中的数据

获取一行值:

hbase:043:0> get 'Student','0001'
COLUMN                                        CELL
 Grades:BigData                               timestamp=2021-07-19T20:31:39.473, value=80
 Grades:Computer                              timestamp=2021-07-19T20:31:39.491, value=90
 Grades:Math                                  timestamp=2021-07-19T20:31:41.910, value=85
 Stulnfo:Name                                 timestamp=2021-07-19T20:32:27.004, value=Jim Green\x0A
1 row(s)
Took 0.0111 seconds

获取某一个列族的值

hbase:045:0> get 'Student', '0001', {COLUMN => 'Grades'}
COLUMN                                        CELL
 Grades:BigData                               timestamp=2021-07-19T20:31:39.473, value=80
 Grades:Computer                              timestamp=2021-07-19T20:31:39.491, value=90
 Grades:Math                                  timestamp=2021-07-19T20:31:41.910, value=85
1 row(s)
Took 0.0074 seconds
hbase:046:0>

获取某个时间段的数据

hbase:046:0> get 'Student', '0001', {COLUMN => 'Grades',TIMERANGE =>[1626630169000,1626698581000]}
COLUMN                                        CELL
 Grades:BigData                               timestamp=2021-07-19T20:31:39.473, value=80
 Grades:Computer                              timestamp=2021-07-19T20:31:39.491, value=90
 Grades:Math                                  timestamp=2021-07-19T20:31:41.910, value=85
1 row(s)
Took 0.0079 seconds
hbase:047:0>

获取3个版本的值

hbase:054:0> get 'Student', '0001', {COLUMN => 'Grades', VERSIONS => 3}
COLUMN                                        CELL
 Grades:BigData                               timestamp=2021-07-19T20:31:39.473, value=80
 Grades:Computer                              timestamp=2021-07-19T20:31:39.491, value=90
 Grades:Math                                  timestamp=2021-07-19T20:31:41.910, value=85
1 row(s)
Took 0.0070 seconds
hbase:055:0>

获取某个大于某值的值

hbase:056:0> get 'Student', '0001' ,{FILTER=>"ValueFilter(=, 'binary:80')"}
COLUMN                                        CELL
 Grades:BigData                               timestamp=2021-07-19T20:31:39.473, value=80
1 row(s)
Took 0.0511 seconds
hbase:057:0> get 'Student', '0001' ,{FILTER=>"ValueFilter(>, 'binary:80')"}
COLUMN                                        CELL
 Grades:Computer                              timestamp=2021-07-19T20:31:39.491, value=90
 Grades:Math                                  timestamp=2021-07-19T20:31:41.910, value=85
 Stulnfo:Name                                 timestamp=2021-07-19T20:32:27.004, value=Jim Green\x0A
1 row(s)
Took 0.0049 seconds
hbase:058:0> get 'Student', '0001' ,{FILTER=>"ValueFilter(>=, 'binary:80')"}
COLUMN                                        CELL
 Grades:BigData                               timestamp=2021-07-19T20:31:39.473, value=80
 Grades:Computer                              timestamp=2021-07-19T20:31:39.491, value=90
 Grades:Math                                  timestamp=2021-07-19T20:31:41.910, value=85
 Stulnfo:Name                                 timestamp=2021-07-19T20:32:27.004, value=Jim Green\x0A
1 row(s)
Took 0.0055 seconds
hbase:059:0>

获取某一列的值

hbase:063:0> get 'Student', '0001', {COLUMN => 'Grades:Math', VERSIONS => 3}
COLUMN                                        CELL
 Grades:Math                                  timestamp=2021-07-19T20:31:41.910, value=85
1 row(s)
Took 0.0064 seconds
hbase:064:0>


这篇关于Hbase-03-shell get 命令的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程