1/5 HBase( 七 )

5.5.3  获取数据get# 语法get '表名', '行键'# 示例get 'users', 'xiaoming'

根据某一行某列族的数据
# 语法get '表名', '行键', '列族名'# 示例get 'users', 'xiaoming', 'info'# 创建表,c1版本为4 ,  元数据mykey=myvaluehbase(main):009:0> create 't1', {NAME => 'c1', VERSIONS => 4}, METADATA => { 'mykey' => 'myvalue' }0 row(s) in 2.2810 seconds=> Hbase::Table - t1# 添加列族c2, c3hbase(main):010:0> alter 't1', 'c2', 'c3'Updating all regions with the new schema...1/1 regions updated.Done.Updating all regions with the new schema...1/1 regions updated.Done.0 row(s) in 3.8320 seconds# 出入数据,c1 插入4个版本的值hbase(main):011:0> put 't1', 'r1', 'c1', 'v1'0 row(s) in 0.1000 secondshbase(main):012:0> put 't1', 'r1', 'c1', 'v11'0 row(s) in 0.0180 secondshbase(main):013:0> put 't1', 'r1', 'c1', 'v111'0 row(s) in 0.0140 secondshbase(main):014:0> put 't1', 'r1', 'c1', 'v1111'0 row(s) in 0.0140 seconds# 插入c2、c3的值hbase(main):015:0> put 't1', 'r1', 'c2', 'v2'0 row(s) in 0.0140 secondshbase(main):016:0> put 't1', 'r1', 'c3', 'v3'0 row(s) in 0.0210 seconds# 获取rowKey=r1的一行记录hbase(main):017:0> get 't1', 'r1'COLUMN                                              CELL c1:                                                timestamp=1552819382575, value=https://www.huyubaike.com/biancheng/v1111 c2: timestamp=1552819392398, value=v2 c3: timestamp=1552819398244, value=v33 row(s) in 0.0550 seconds# 获取rowKey=r1并且 1552819392398 <= 时间戳范围 < 1552819398244hbase(main):018:0> get 't1', 'r1', {TIMERANGE => [1552819392398, 1552819398244]}COLUMN CELL c2: timestamp=1552819392398, value=v21 row(s) in 0.0090 seconds# 获取指定列的值hbase(main):019:0> get 't1', 'r1', {COLUMN => 'c1'}COLUMN CELL c1: timestamp=1552819382575, value=v11111 row(s) in 0.0160 seconds# 获取指定列的值,多个值使用数组表示hbase(main):020:0> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']}COLUMN CELL c1: timestamp=1552819382575, value=v1111 c2: timestamp=1552819392398, value=v2 c3: timestamp=1552819398244, value=v33 row(s) in 0.0170 seconds# 获取c1的值,获取4个版本的值,默认是按照时间戳降续排序的hbase(main):021:0> get 't1', 'r1', {COLUMN => 'c1', VERSIONS => 4}COLUMN CELL c1: timestamp=1552819382575, value=v1111 c1: timestamp=1552819376343, value=v111 c1: timestamp=1552819368993, value=v11 c1: timestamp=1552819362975, value=v14 row(s) in 0.0180 seconds# 获取c1的3个版本值hbase(main):027:0* get 't1', 'r1', {COLUMN => 'c1', VERSIONS => 3}COLUMN CELL c1: timestamp=1552819382575, value=v1111 c1: timestamp=1552819376343, value=v111 c1: timestamp=1552819368993, value=v113 row(s) in 0.0090 seconds# 获取指定时间戳版本的列hbase(main):022:0> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => 1552819376343}COLUMN CELL c1: timestamp=1552819376343, value=v1111 row(s) in 0.0170 secondshbase(main):023:0> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => 1552819376343, VERSIONS => 4}COLUMN CELL c1: timestamp=1552819376343, value=v1111 row(s) in 0.0130 seconds# 获取rowKey=r1中的值等于v2的所有列hbase(main):024:0> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:v2')"}COLUMN CELL c2: timestamp=1552819392398, value=v21 row(s) in 0.0510 secondshbase(main):025:0> get 't1', 'r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}}COLUMN CELL c1: timestamp=1552819382575, value=v11111 row(s) in 0.0100 seconds

推荐阅读