本地操作

  • 启动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的更多相关文章

  1. python 操作 hbase

    python 是万能的,当然也可以通过api去操作big database 的hbase了,python是通过thrift去访问操作hbase 以下是在centos7 上安装操作,前提是hbase已经 ...

  2. 【Hbase三】Java,python操作Hbase

    Java,python操作Hbase 操作Hbase python操作Hbase 安装Thrift之前所需准备 安装Thrift 产生针对Python的Hbase的API 启动Thrift服务 执行p ...

  3. Hbase理论&&hbase shell&&python操作hbase&&python通过mapreduce操作hbase

    一.Hbase搭建: 二.理论知识介绍: 1Hbase介绍: Hbase是分布式.面向列的开源数据库(其实准确的说是面向列族).HDFS为Hbase提供可靠的底层数据存储服务,MapReduce为Hb ...

  4. Python操作HBase之happybase

    安装Thrift 安装Thrift的具体操作,请点击链接 pip install thrift 安装happybase pip install happybase 连接(happybase.Conne ...

  5. python 操作Hbase 详解

    博文参考:https://www.cnblogs.com/tashanzhishi/p/10917956.html 如果你们学习过Python,可以用Python来对Hbase进行操作. happyb ...

  6. 通过Python操作hbase api

    # coding=utf-8 # Author: ruin """ discrible: """ from thrift.transport ...

  7. 大数据自学5-Python操作Hbase

    在Hue环境中本身是可以直接操作Hbase数据库的,但是公司的环境不知道什么原因一直提示"Api Error:timed out",进度条一直在跑,却显示不出表. 但是在CDH后台 ...

  8. python连接hbase

    安装HBase HBase是一个构建在HDFS上的分布式列存储系统,主要用于海量结构化数据存储.这里,我们的目标只是为Python访问HBase提供一个基本的环境,故直接下载二进制包,采用单机安装.下 ...

  9. Python之操作HBASE数据库

    目前有两个库可以操作HBASE:hbase-thrift 和  happybase happybase使用起来比较简单方便,因此重点学习该库,hbase-thrift只做简要介绍. (一)hbase- ...

随机推荐

  1. Java VisualVM 插件地址

    打开Java VisualVM检查更新插件时,默认的连接连不上,通过浏览器访问之后发现默认的服务器已经404,新地址已经迁移到github,下面这个地址里面有不同版本jdk对应的插件中心地址. htt ...

  2. hdu 1495 (搜索) 非常可乐

    http://acm.hdu.edu.cn/showproblem.php?pid=1495 搜索模拟出每此倒得情况就好,详情见代码\ (好困啊!!!!1) #include<cstdio> ...

  3. django基础使用

    //创建应用 python3 manage.py startapp mysite //开启服务 python3 manage.py runserver 127.0.0.1:8080 //创建数据库命令 ...

  4. 使用scrollTop返回顶部

    scrollTop属性表示被隐藏在内容区域上方的像素数.元素未滚动时,scrollTop的值为0,如果元素被垂直滚动了,scrollTop的值大于0,且表示元素上方不可见内容的像素宽度 由于scrol ...

  5. 微信小程序获取当前位置

    详细参数说明请看小程序api文档:https://developers.weixin.qq.com/miniprogram/dev/api/wx.openLocation.html wx.getLoc ...

  6. mybatis 操作数据错误Truncated incorrect DOUBLE value: ''

    网上查到遇到次错误造成的原因: UPDATE TSYS_ROLE_RIGHTSET ACTIVE_FLAG = '2' and UPDATE_PERSON = 'CaiYiHua' and  UPDA ...

  7. 如何用xx-net上youtube

    1.下载https://github.com/XX-net/XX-Net/blob/master/code/default/download.md   里面的稳定版本 2.下载chrome.百度chr ...

  8. centOS 6.5下升级mysql,从5.1升级到5.6

    转载:https://www.cnblogs.com/vickygu2007/p/5066409.html #mysqldump -uroot -p --all-databases > data ...

  9. mysql里几个超时配置参数wait_timeout,net_read_timeout等

    以下这些配置项单位都是秒,在mysql命令行中可以使用show global variables like '变量名';可查询配置值. connect_timeout:连接响应超时时间.服务器端在这个 ...

  10. java JNI 实现原理 (二) Linux 下如何 load JNILibrary

    在博客java JNI (一)虚拟机中classloader的JNILibrary 中讨论了java中的Library 是由classloader 来load的,那我们来看看 classloader是 ...