博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hbase之python利用thrift操作hbase数据和shell操作
阅读量:7036 次
发布时间:2019-06-28

本文共 3960 字,大约阅读时间需要 13 分钟。

前沿:

        以前都是用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> 

原文:


#可以看到历史版本记录

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是实现了序列化,传输,协议定义,远程调用等功能,跨语言能力更多。某些方面二者可以互相替代,但一些方面则各有适用范围。

原文:


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

1
2
3
4
5
6
7
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模块 ~

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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()

原文:


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

 本文转自 rfyiamcool 51CTO博客,原文链接:http://blog.51cto.com/rfyiamcool/1537505,如需转载请自行联系原作者

你可能感兴趣的文章
CCLayer设置anchorPoint无效的问题
查看>>
bash shell 中的比较
查看>>
JavaScript 作用域
查看>>
Linux权限管理
查看>>
Bochs下编译安装Linux-0.11版本
查看>>
让tomcat 日志网页中显示
查看>>
Linux Ubuntu 16.04 主机名设置
查看>>
解码,
查看>>
CCNP 静态路由
查看>>
单链表二[不带头节点链表]
查看>>
xml解析——增删改查操作后将其修改结果保存
查看>>
49.C#--多态之抽象类
查看>>
Html中居中问题小结
查看>>
Spring mvc 拦截器
查看>>
MySQL GROUP BY 和GROUP_CONCAT的一些用法
查看>>
关于box2d的例子testbed
查看>>
## mysqldump 导出数据库各参数详细说明
查看>>
2.5.3 svn文件
查看>>
python
查看>>
43.防盗链配置、访问控制Directory、访问控制FilesMatch
查看>>