python操作Hbase导入导出

我现在要把数据从正式服中获取,然后在从测试服中存储

import happybase
import requests
import json


port_hbase=9090
host_hbase='你的正式服ip'

def scanner(table='DATAETL:RPT',start='',end='',*args,**kwrgs):
    c=happybase.Connection(host_hbase,port_hbase)
    t=c.table(table)
    return t.scan(*args,**kwrgs,row_start=start,row_stop=end)

def hbase_save(table='DATAETL:RPT',key='',row='',*args,**kwrgs):
    c=happybase.Connection("你的测试服ip",9090)
    t=c.table(table)
    t.put(key,row)

row_start='2019-10-17_41898936'
row_end='2019-10-17_41898937'

for key,row in scanner(start=row_start,end=row_end):
        hbase_save(key=key,row=row)

查询一下,看看ok不, 这里只用扫描一下测试服的这个rowkey

import happybase
import requests
import json


port_hbase=9090
host_hbase='你的测试服ip'

def scanner(table='DATAETL:RPT',start='',end='',*args,**kwrgs):
    c=happybase.Connection(host_hbase,port_hbase)
    t=c.table(table)
    return t.scan(*args,**kwrgs,row_start=start,row_stop=end)


row_start='2019-10-17_41898936'
row_end='2019-10-17_41898937'

for key,row in scanner(start=row_start,end=row_end):
        print(key)
        

成功!

发布了103 篇原创文章 · 获赞 23 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_38403590/article/details/103910820