php – 如何清除hbase中的表?
发布时间:2020-12-13 13:02:32 所属栏目:PHP教程 来源:网络整理
导读:我想在hbase中清空一个表…例如:user.是否有任何命令或函数来清空表而不删除它… 我的表结构是: $mutations = array( new Mutation( array( 'column' = 'username:1','value' =$name ) ),new Mutation( array( 'column' = 'email:1','value' =$email ) ) )
|
我想在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);
有人能帮我吗?
没有单一命令可以清除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);
如果表中没有大量数据 – 扫描所有行并删除每个行的速度要快得多. $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);
}
在这种情况下,数据不会被物理删除,实际上它被“标记为已删除”并保留在表中直到下一个主要契约. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
