1. 程式人生 > >HBase刪除表中資料

HBase刪除表中資料

1、使用hbase shell中delete命令刪除表中特定的單元格資料,命令格式如下:

delete 'tablename','row','column name','time stramp'

刪除emp表中第二行personal data:name列、時間節點為1502182102866的記錄:

delete 'emp','2','personal data:name',1502182102866

刪除表中的所有單元格,命令格式如下:

deleteall 'tablename','row'

刪除emp表中第二行資料:

deleteall 'emp','2'

2、使用python thrift API刪除表資料,程式碼如下:
首先在empbypy表中新增一行資料,作為測試

# coding=utf-8
from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import TBufferedTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase

from hbase.ttypes import *

# 主機地址及埠號,埠號預設為9090
host = '192.168.83.135'
port = 9090

# 初始化連結
transport = TBufferedTransport(TSocket(host, port))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)

# 建立客戶端
client = Hbase.Client(protocol) print client.getRow('empbypy','2') client.deleteAll('empbypy','2','personal data:city') print client.getRow('empbypy','2') client.deleteAllRow('empbypy','2') print client.getRow('empbypy','2') transport.close()

執行結果如下:
這裡寫圖片描述