我想在hbase中清空一个表...例如:user.是否有任何命令或函数来清空表而不删除它...
我的表结构是:
$mutations = array(
new Mutation( array(
'column' => 'username:1',
'value' =>$name
) ),
new Mutation( array(
'column' => 'email:1',
'value' =>$email
) )
);
$hbase->mutateRow("user",$key,$mutations);
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?
Ale*_*rra 58
如果你在HBase shell中执行它:
> truncate 'yourTableName'
Run Code Online (Sandbox Code Playgroud)
然后HBase将对'yourTableName'执行此操作:
> disable 'yourTableName'
> drop 'yourTableName'
> create 'yourTableName', 'f1', 'f2', 'f3'
Run Code Online (Sandbox Code Playgroud)
另一个有效的选择是实际删除表,然后使用与前一个相同的设置重建另一个表.
我不知道如何在PHP中执行此操作,但我知道如何在Java中执行此操作.php中的相应操作应该类似,您只需要检查API的外观.
在Java中使用HBase 0.90.4:
// Remember the "schema" of your table
HBaseAdmin admin = new HBaseAdmin(yourConfiguration);
HTableDescriptor td = admin.getTableDescriptor(Bytes.toBytes("yourTableName");
// Delete your table
admin.disableTable("yourTableName");
admin.deleteTable("yourTableName");
// Recreate your talbe
admin.createTable(td);
Run Code Online (Sandbox Code Playgroud)
sta*_*1ng -4
没有单个命令可以清除 Hbase 表,但您可以使用 2 种解决方法:禁用、删除、创建表或扫描所有记录并删除每条记录。
实际上,禁用、删除和再次创建表大约需要 4 秒。
// get Hbase client
$client = <Your code here>;
$t = "table_name";
$tables = $client->getTableNames();
if (in_array($t, $tables)) {
if ($client->isTableEnabled($t))
$client->disableTable($t);
$client->deleteTable($t);
}
$descriptors = array(
new ColumnDescriptor(array("name" => "c1", "maxVersions" => 1)),
new ColumnDescriptor(array("name" => "c2", "maxVersions" => 1))
);
$client->createTable($t, $descriptors);
Run Code Online (Sandbox Code Playgroud)
如果表中数据不多 - 扫描所有行并删除每一行会快得多。
$client = <Your code here>;
$t = "table_name";
// i don't remember, if list of column families is actually needed here
$columns = array("c1", "c2");
$scanner = $client->scannerOpen($t, "", $columns);
while ($result = $client->scannerGet($scanner)) {
$client->deleteAllRow($t, $result[0]->row);
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,数据不会被物理删除,实际上它被“标记为已删除”并保留在表中直到下一个主要契约。
| 归档时间: |
|
| 查看次数: |
24604 次 |
| 最近记录: |