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()
运行结果如下: