hbase之python利用thrift操作hbase数据和shell操作
admin
2023-02-08 10:20:09
0次

前沿:

        以前都是用mongodb的,但是量大了,mongodb显得不那么靠谱,改成hbase撑起一个量级。


HBase是Apache Hadoop的数据库,能够对大型数据提供随机、实时的读写访问。HBase的目标是存储并处理大型的数据。HBase是一个开源的,分布式的,多版本的,面向列的存储模型。它存储的是松散型数据。

HBase提供了丰富的访问接口。

HBase Shell
Java clietn API
Jython、Groovy DSL、Scala
REST
Thrift(Ruby、Python、Perl、C++…)
MapReduce
Hive/Pig


hbase(main):001:0> 

#创建表

hbase(main):002:0* create 'blog','info','content'

0 row(s) in 2.0290 seconds

#查看表

hbase(main):003:0> list

TABLE                                                                           

blog                                                                            

test_standalone                                                                 

2 row(s) in 0.0270 seconds

#增添数据

hbase(main):004:0> put 'blog','1','info:editor','liudehua'

0 row(s) in 0.1340 seconds


hbase(main):005:0> put 'blog','1','info:address','bj'

0 row(s) in 0.0070 seconds


hbase(main):006:0> put 'blog','1','content:header','this is header'

0 row(s) in 0.0070 seconds


hbase(main):007:0> 

hbase(main):008:0* 

hbase(main):009:0* get 'blog','1'

COLUMN                CELL                                                      

 content:header       timestamp=1407464302384, value=this is header             

 info:address         timestamp=1407464281942, value=bj                         

 info:editor          timestamp=1407464270098, value=liudehua                   

3 row(s) in 0.0360 seconds


hbase(main):010:0> get 'blog','1','info'

COLUMN                                                 CELL                                                                                                                                                         

 info:address                                          timestamp=1407464281942, value=bj                                                                                                                            

 info:editor                                           timestamp=1407464270098, value=liudehua                                                                                                                      

2 row(s) in 0.0120 seconds


#这里是可以按照条件查询的。

hbase(main):012:0* scan 'blog'

ROW                                                    COLUMN+CELL                                                                                                                                                  

 1                                                     column=content:header, timestamp=1407464302384, value=this is header                                                                                         

 1                                                     column=info:address, timestamp=1407464281942, value=bj                                                                                                       

 1                                                     column=info:editor, timestamp=1407464270098, value=liudehua                                                                                                  

1 row(s) in 0.0490 seconds


hbase(main):013:0> 

hbase(main):014:0* put 'blog','1','content:header','this is header2'

0 row(s) in 0.0080 seconds


hbase(main):015:0> 

hbase(main):016:0* 

hbase(main):017:0* put 'blog','1','content:header','this is header3'

0 row(s) in 0.0050 seconds


hbase(main):018:0> scan 'blog'

ROW                                                    COLUMN+CELL                                                                                                                                                  

 1                                                     column=content:header, timestamp=1407464457128, value=this is header3                                                                                        

 1                                                     column=info:address, timestamp=1407464281942, value=bj                                                                                                       

 1                                                     column=info:editor, timestamp=1407464270098, value=liudehua                                                                                                  

1 row(s) in 0.0180 seconds



hbase(main):020:0> get 'blog','1','content:header'

COLUMN                                                 CELL                                                                                                                                                         

 content:header                                        timestamp=1407464457128, value=this is header3                                                                                                               

1 row(s) in 0.0090 seconds


hbase(main):021:0> 

原文:http://rfyiamcool.blog.51cto.com/1030776/1537505


#可以看到历史版本记录

hbase(main):022:0* get 'blog','1',{COLUMN => 'content:header',VERSIONS => 2}

COLUMN                                                 CELL                                                                                                                                                         

 content:header                                        timestamp=1407464457128, value=this is header3                                                                                                               

 content:header                                        timestamp=1407464454648, value=this is header2                                                                                                               

2 row(s) in 0.0100 seconds

#可以看到历史版本记录

hbase(main):023:0> get 'blog','1',{COLUMN => 'content:header',VERSIONS => 3}

COLUMN                                                 CELL                                                                                                                                                         

 content:header                                        timestamp=1407464457128, value=this is header3                                                                                                               

 content:header                                        timestamp=1407464454648, value=this is header2                                                                                                               

 content:header                                        timestamp=1407464302384, value=this is header                                                                                                                

3 row(s) in 0.0490 seconds


hbase(main):024:0> 


base用java来操作是最方便,也效率最高的方式。但java并非轻量级,不方便在任何环境下调试。而且不同的开发人员熟悉的语言不一样,开发效率也不一样。hbase 通过thrift,还可以用python,ruby,cpp,perl等语言来操作。


thrift是facebook开发开源的类似google的protobuf的远程调用组件。但protobuf只有数据的序列化,且只支持二进制协议,没有远程调用部分。protobuf原生支持cpp,python,java,另外还有第三方实现的objectc,ruby等语言。而thrift是实现了序列化,传输,协议定义,远程调用等功能,跨语言能力更多。某些方面二者可以互相替代,但一些方面则各有适用范围。

原文:http://rfyiamcool.blog.51cto.com/1030776/1537505


thrift的安装及thrift python的相关模块 ~

http://www.apache.org/dist//thrift/0.9.1/thrift-0.9.1.tar.gz
tar zxvf thrift-0.8.0.tar.gz
cd thrift-0.8.0
./configure -with-cpp=no
make
sudo make install
sudo pip install thrift


这里是可以生成python的thrift和hbase模块 ~

thrift -gen py /home/ubuntu/hbase-0.98.1/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift


hbase之python利用thrift操作hbase数据和shell操作


from thrift.transport import TSocket

from thrift.protocol import TBinaryProtocol

from hbase import Hbase

transport=TSocket.TSocket('localhost',9090)

protocol=TBinaryProtocol.TBinaryProtocol(transport)

client=Hbase.Client(protocol)

transport.open()

client.getTableNames()


原文:http://rfyiamcool.blog.51cto.com/1030776/1537505


hbase 0.98的版本 貌似没有thrift的相关组建,我这里的用的是0.94版本搞定的。  


相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...