python操作Hbase
本地操作
启动thrift服务:./bin/hbase-daemon.sh start thrift
hbase模块产生:
下载thrfit源码包:thrift-0.8.0.tar.gz
解压安装
./configure
make
make install
在thrift-0.8.0目录中,lib/py/build/lib.linux-x86_64-2.6/目录下存在thrift的python模块,拷贝出来即可
生成hbase模块
下载源码包:hbase-0.98.24-src.tar.gz
解压,进入下面目录:hbase-0.98.24/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift
thrift --gen py Hbase.thrift
创建表格
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
transport = TSocket.TSocket('master' , 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Hbase.Client(protocol)
transport.open()
base_info_contents = ColumnDescriptor(name='meta-data',maxVersions=1)
other_info_contents = ColumnDescriptor(name='flags',maxVersions=1)
client.createTable('new_music_table', [base_info_contents, other_info_contents])
print client.getTableNames()写数据
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
transport = TSocket.TSocket('master' , 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Hbase.Client(protocol)
transport.open()
tableName = 'new_music_table'
rowKey = '1100'
mutations = [Mutation(column="meta-data:name" , value="wangqingshui"),\
Mutation(column="meta-data:tag" , value="pop"),\
Mutation(column="meta-data:is_valid" , value="TRUE")]
client.mutateRow(tableName,rowKey,mutations,None)读数据
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
transport = TSocket.TSocket('master' , 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Hbase.Client(protocol)
transport.open()
tableName = 'new_music_table'
rowKey = '1100'
result = client.getRow(tableName,rowKey,None)
for r in result:
print 'the row is ',r.row
print 'the name is ',r.columns.get('meta-data:name').value
print 'the name is ',r.columns.get('meta-data:is_valid').value读多条数据
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *
transport = TSocket.TSocket('master' , 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Hbase.Client(protocol)
transport.open()
tableName = 'new_music_table'
scan = TScan()
id = client.scannerOpenWithScan(tableName , scan , None)
result = client.scannerGetList(id,10)
for r in result:
print '==============='
print 'the row is ' , r.row
for k,v in r.columns.items():
print "\t".join([k,v.value])
# 执行结果
===============
the row is 1100
meta-data:name wangqingshui
meta-data:is_valid TRUE
meta-data:tag pop
===============
the row is 2200
meta-data:name langdechuanshuo
python操作Hbase的更多相关文章
- python 操作 hbase
python 是万能的,当然也可以通过api去操作big database 的hbase了,python是通过thrift去访问操作hbase 以下是在centos7 上安装操作,前提是hbase已经 ...
- 【Hbase三】Java,python操作Hbase
Java,python操作Hbase 操作Hbase python操作Hbase 安装Thrift之前所需准备 安装Thrift 产生针对Python的Hbase的API 启动Thrift服务 执行p ...
- Hbase理论&&hbase shell&&python操作hbase&&python通过mapreduce操作hbase
一.Hbase搭建: 二.理论知识介绍: 1Hbase介绍: Hbase是分布式.面向列的开源数据库(其实准确的说是面向列族).HDFS为Hbase提供可靠的底层数据存储服务,MapReduce为Hb ...
- Python操作HBase之happybase
安装Thrift 安装Thrift的具体操作,请点击链接 pip install thrift 安装happybase pip install happybase 连接(happybase.Conne ...
- python 操作Hbase 详解
博文参考:https://www.cnblogs.com/tashanzhishi/p/10917956.html 如果你们学习过Python,可以用Python来对Hbase进行操作. happyb ...
- 通过Python操作hbase api
# coding=utf-8 # Author: ruin """ discrible: """ from thrift.transport ...
- 大数据自学5-Python操作Hbase
在Hue环境中本身是可以直接操作Hbase数据库的,但是公司的环境不知道什么原因一直提示"Api Error:timed out",进度条一直在跑,却显示不出表. 但是在CDH后台 ...
- python连接hbase
安装HBase HBase是一个构建在HDFS上的分布式列存储系统,主要用于海量结构化数据存储.这里,我们的目标只是为Python访问HBase提供一个基本的环境,故直接下载二进制包,采用单机安装.下 ...
- Python之操作HBASE数据库
目前有两个库可以操作HBASE:hbase-thrift 和 happybase happybase使用起来比较简单方便,因此重点学习该库,hbase-thrift只做简要介绍. (一)hbase- ...
随机推荐
- sql 查询某个字段出现的次数
表名随便起个 testtable 那么有这么一个需求,利用你所学的sql语句 单表查询出下表的结果 也就是统计某个时间某个值出现的次数其实一开始我是很懵,毕竟之前也没做过,只能怪自己学得太浅了.过后我 ...
- make V=1 查看完整的gcc编译信息
Linux内核make命令选项 2012年5月28日lenky发表评论阅读评论6,289 次浏览 升级Linux内核的操作已经变得很简单,基本的几个命令即可搞定:make menuconfig.m ...
- Real-time qPCR So Easy?
Real-time qPCR So Easy? [2016-05-27] 实时荧光定量PCR技术是在定性RCR技术基础上发展起来的核酸定量技术,于1996年由美国Applied biosy ...
- Linux中处理字符串
获取字符串长度: ${#字符串变量名} 截取子串: 1. expr substr 字符串 起始位置 截取长度 2. 命令输出 | cut -c 起始位置-结束位置 命令输出 | cut -c &quo ...
- [Jmeter] Concurrency Thread Group
Concurrency Thread Group : https://jmeter-plugins.org/wiki/ConcurrencyThreadGroup/ 参数介绍: Target Conc ...
- java 多态的深入理解
简单来说 : 多态 能够很好的解决代码耦合性的问题 考虑这样一个场景 有个人 买了辆捷达汽车 .这个系统应该如何设计呢? public class JettaCar { public void run ...
- Zxing2.1扫描取景框变形问题解决
修改竖屏扫描的贴子,2.0之前的都很适用.可是到了2.1,有些贴子的做法可以将扫描框改为竖屏,但是取景框里扫描到的东西是变形的(扁的),本人仔细研究一番,终于解决了这个问题,下面贴出解决办法: 1.修 ...
- ueditor 上传图片
ueditor在配置图片,附件上传 首先,是以web项目为基础的,需要安装好eclipse以及tomcat 其次,需要下载ueditor(可去百度官网下载 http://ueditor.baidu. ...
- Navicat for MySQL连接出错:1251
平台:window10 x64+mysql-8.0.15-winx64+navicat_trial_11.1.20.0(PatchNavicat破解) 错误提示:1251-Client does no ...
- oracle 锁表查看与解锁
查看被锁的表: select l.session_id,o.owner,o.object_name from v$locked_object l,dba_objects o where l.objec ...