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- ...
随机推荐
- The valid characters are defined in RFC 7230 and RFC 3986问题
这个问题困扰了我接近两天了!尼玛!网上搜了很多资料,有的给出了解决方案,然后下面的评论说按照楼主做的,没有成功,我一做也确实没有成功.设置了断点,一步一步跟进去看,还是没有头绪.不过有一点可以确认的是 ...
- CreateToolhelp32Snapshot 以及 EnumProcesses
RT,请教如何获得Windows任务管理器中所显示的进程列表. CreateToolhelp32Snapshot 以及 EnumProcesses 这些方法我都试过了,但是这两种方法得到的结果和任务管 ...
- Spring MVC 注解类型
Spring 2.5 引入了注解 基于注解的控制器的优势 1. 一个控制器类可以处理多个动作,而一个实现了 Controller 接口的控制器只能处理一个动作 2. 基于注解的控制器的请求映射不需要存 ...
- 论坛:Error:No result defined for action cn.itcast.oa.view.action.TopicAction and result
使用了<s:hidden name="forumId" value="#forum.id"/> 可以改为: <s:hidden name=&q ...
- 后期生成事件命令copy /y
copy /y $(TargetDir)7z.dll ..\..\..\..\webapp\bin copy /y $(TargetDir)7z64.dll ..\..\..\..\webapp\bi ...
- oracle导入sql文件关闭回馈
set feedback off --关闭回馈 set define off --关闭转义关键字
- 【Web】CSS实现绝对定位元素水平垂直居中
网页中常常需用让绝对定位元素水平垂直居中,下面介绍2种方法: 一 元素宽度未知 <!DOCTYPE html> <html lang="en"> <h ...
- 3、iOS Xcode创建protocol(代理).h文件
- php获取响应状态码
$ch = curl_init('http://www.jb51.net'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); ...
- stacking过程
图解stacking原理: 上半部分是用一个基础模型进行5折交叉验证,如:用XGBoost作为基础模型Model1,5折交叉验证就是先拿出四折作为training data,另外一折作为testing ...