在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 大數(shù)據(jù)/ HBase刪除數(shù)據(jù)
HBase禁用表
HBase創(chuàng)建表
HBase客戶端API
HBase安裝
HBase表描述和修改
HBase Admin API
HBase掃描
HBase創(chuàng)建數(shù)據(jù)
HBase列出表
HBase刪除數(shù)據(jù)
HBase讀取數(shù)據(jù)
HBase常用命令
HBase更新數(shù)據(jù)
HBase關(guān)閉
HBase架構(gòu)
HBase Shell
HBase Exists
HBase安全
HBase教程
HBase啟用表
HBase計(jì)數(shù)和截?cái)?/span>
HBase刪除表

HBase刪除數(shù)據(jù)

從表刪除特定單元格

使用 delete 命令,可以在一個(gè)表中刪除特定單元格。 delete 命令的語法如下:

delete ‘<table name>’, ‘<row>’, ‘<column name >’, ‘<time stamp>’

下面是一個(gè)刪除特定單元格和例子。在這里,我們刪除salary

hbase(main):006:0> delete 'emp', '1', 'personal data:city',
1417521848375
0 row(s) in 0.0060 seconds

刪除表的所有單元格

使用“deleteall”命令,可以刪除一行中所有單元格。下面給出是 deleteall 命令的語法。

deleteall ‘<table name>’, ‘<row>’,

這里是使用“deleteall”命令刪去 emp 表 row1 的所有單元的一個(gè)例子。

hbase(main):007:0> deleteall 'emp','1'
0 row(s) in 0.0240 seconds

使用scan命令驗(yàn)證表。表被刪除后的快照如下。

hbase(main):022:0> scan 'emp'

ROW                  COLUMN+CELL

2 column=personal data:city, timestamp=1417524574905, value=chennai 

2 column=personal data:name, timestamp=1417524556125, value=ravi

2 column=professional data:designation, timestamp=1417524204, value=sr:engg

2 column=professional data:salary, timestamp=1417524604221, value=30000

3 column=personal data:city, timestamp=1417524681780, value=delhi

3 column=personal data:name, timestamp=1417524672067, value=rajesh

3 column=professional data:designation, timestamp=1417523187, value=jr:engg

3 column=professional data:salary, timestamp=1417524702514, value=25000

使用Java API刪除數(shù)據(jù)

可以從使用HTable類的delete()方法刪除HBase表數(shù)據(jù)。按照下面給出從表中刪除數(shù)據(jù)的步驟。

第1步:實(shí)例化Configuration類

Configuration類增加了HBase配置文件到它的對象??梢詣?chuàng)建使用HbaseConfiguration類的create()方法,如下圖所示的Configuration 對象。

Configuration conf = HbaseConfiguration.create();

第2步:實(shí)例化HTable類

有一個(gè)類叫HTable,實(shí)現(xiàn)在HBase中的Table類。此類用于單個(gè)HBase的表進(jìn)行通信。在這個(gè)類實(shí)例,它接受配置對象和表名作為參數(shù)。實(shí)例化HTable類,如下圖所示。

HTable hTable = new HTable(conf, tableName); 

第3步:實(shí)例化Delete 類

通過傳遞將要?jiǎng)h除的行的行ID,在字節(jié)數(shù)組格式實(shí)例化Delete類。也可以通過構(gòu)造時(shí)間戳和Rowlock。

Delete delete = new Delete(toBytes("row1"));

第4步:選擇刪除數(shù)據(jù)

可以使用Delete類的delete方法刪除數(shù)據(jù)。這個(gè)類有各種刪除方法。選擇使用這些方法來刪除列或列族。這里顯示Delete類方法的用法在下面的例子。

delete.deleteColumn(Bytes.toBytes("personal"), Bytes.toBytes("name"));
delete.deleteFamily(Bytes.toBytes("professional"));

第5步:刪除數(shù)據(jù)

通過HTable類實(shí)例的delete()方法,如下所示刪除所選數(shù)據(jù)。

table.delete(delete); 

第6步:關(guān)閉HTable實(shí)例

刪除數(shù)據(jù)后,關(guān)閉HTable實(shí)例。

table.close();

下面給出的是從HBase表中刪除的數(shù)據(jù)的完整程序。

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import